-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateTable.js
More file actions
122 lines (121 loc) · 4.41 KB
/
Copy pathcreateTable.js
File metadata and controls
122 lines (121 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
function createTable(values, nameUse){
let messages = values.messages;
let globalVs = values.globalVar;
let betTrackAr = values.betTrackAr;
let commCards = values.cards;
let oldTable = document.getElementById('myTable');
if (oldTable) oldTable.remove();
let oldCommCardsTable = document.getElementById('commCardsTable');
if (oldCommCardsTable) oldCommCardsTable.remove();
let commCardsTable = document.createElement('table');
commCardsTable.id = 'commCardsTable';
let everyoneIsReady = messages.every(msg => msg.ready === 'yes');
let headers = ['Player#', 'Name', 'User ID'];
let checkShow = false;
let readyButton = document.getElementById("readyB");
let roundTxt = document.getElementById("roundN");
let potTxt = document.getElementById("potAm");
if (everyoneIsReady) {
headers.push('Card #1', 'Suit #1', 'Card #2', 'Suit #2', 'Chips', 'Turn');
readyButton.style.display = "none";
commCardsTable.style.display = "block";
roundTxt.innerHTML = "Round: " + globalVs[0].round;
roundTxt.style.display = "block";
potTxt.innerHTML = "Pot: " + globalVs[0].pot;
potTxt.style.display = "block";
} else {
headers.push('Ready');
commCardsTable.style.display = "none";
readyButton.style.display = "block";
roundTxt.style.display = "none";
potTxt.style.display = "none";
}
let table = document.createElement('table');
table.id = 'myTable';
let thead = document.createElement('thead');
let headerRow = document.createElement('tr');
headers.forEach(header => {
let th = document.createElement('th');
th.textContent = header;
headerRow.appendChild(th);
});
thead.appendChild(headerRow);
table.appendChild(thead);
let tbody = document.createElement('tbody');
messages.slice(0, 6).forEach((msg, index) => {
let row = document.createElement('tr');
let orderCell = document.createElement('td');
orderCell.textContent = index + 1;
row.appendChild(orderCell);
['name', 'userID'].forEach(key => {
let td = document.createElement('td');
td.textContent = msg[key];
row.appendChild(td);
});
if (everyoneIsReady) {
['cardNumber1', 'suit1', 'cardNumber2', 'suit2'].forEach(key => {
let td = document.createElement('td');
td.textContent = (nameUse == msg.name) ? msg[key] : 'Hidden';
row.appendChild(td);
});
let td = document.createElement('td');
td.textContent = msg.chips;
row.appendChild(td);
td = document.createElement('td');
td.textContent = msg.turn;
if((nameUse == msg.name)&&(msg.turn == 'yes')){
checkShow = true;
}
row.appendChild(td);
} else {
let td = document.createElement('td');
td.textContent = msg.ready;
row.appendChild(td);
}
tbody.appendChild(row);
});
table.appendChild(tbody);
let commCardsHeaders = ['Card#', 'Value', 'Suit'];
let commCardsThead = document.createElement('thead');
let commCardsHeaderRow = document.createElement('tr');
commCardsHeaders.forEach(header => {
let th = document.createElement('th');
th.textContent = header;
commCardsHeaderRow.appendChild(th);
});
commCardsThead.appendChild(commCardsHeaderRow);
commCardsTable.appendChild(commCardsThead);
let commCardsTbody = document.createElement('tbody');
commCards.forEach(card => {
let row = document.createElement('tr');
['id', 'cardNumber', 'suit'].forEach(key => {
let td = document.createElement('td');
td.textContent = card[key];
row.appendChild(td);
});
commCardsTbody.appendChild(row);
});
commCardsTable.appendChild(commCardsTbody);
let checkButton = document.getElementById("checkB");
let betButton = document.getElementById("betB");
let betText = document.getElementById("betAm");
let foldButton = document.getElementById("foldB");
if(checkShow){
if(betTrackAr[betTrackAr.length-1].amount != 0){
checkButton.textContent = "Call";
}else{
checkButton.textContent = "Check"
}
checkButton.style.display = "block";
betButton.style.display = "block";
betText.style.display = "block";
foldButton.style.display = "block";
}else{
checkButton.style.display = "none";
betButton.style.display = "none";
betText.style.display = "none";
foldButton.style.display = "none";
}
document.getElementById('nameShow').insertAdjacentElement("afterend", table);
table.insertAdjacentElement("afterend", commCardsTable);
}