-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
298 lines (258 loc) · 12.6 KB
/
script.js
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
document.addEventListener('DOMContentLoaded', () => {
const seats = document.querySelectorAll('.seat');
const assignDialog = document.getElementById('assign-dialog');
const betDialog = document.getElementById('bet-dialog');
const winLoseDialog = document.getElementById('win-lose-dialog');
const winLoseDialogSecond = document.getElementById('win-lose-dialog-second');
const dealerDialog = document.getElementById('dealer-dialog');
const viewerNameInput = document.getElementById('viewer-name');
const betAmountInput = document.getElementById('bet-amount');
const assignButton = document.getElementById('assign-button');
const placeBetButton = document.getElementById('place-bet-button');
const winButton = document.getElementById('win-button');
const loseButton = document.getElementById('lose-button');
const doubleButton = document.getElementById('double-button');
const splitButton = document.getElementById('split-button');
const pushButton = document.getElementById('push-button');
const blackjackButton = document.getElementById('blackjack-button');
const closeButton = document.getElementById('close-button');
const winButtonSecond = document.getElementById('win-button-second');
const loseButtonSecond = document.getElementById('lose-button-second');
const doubleButtonSecond = document.getElementById('double-button-second');
const pushButtonSecond = document.getElementById('push-button-second');
const blackjackButtonSecond = document.getElementById('blackjack-button-second');
const closeButtonSecond = document.getElementById('close-button-second');
const removePlayerButton = document.getElementById('remove-player-button');
const changeBalanceButton = document.getElementById('change-balance-button');
const newBalanceInput = document.getElementById('new-balance');
const changeBalanceDoneButton = document.getElementById('change-balance-done-button');
const closeBetDialogButton = document.getElementById('close-bet-dialog-button');
const countdownSecondsInput = document.getElementById('countdown-seconds');
const confirmCountdownButton = document.getElementById('confirm-countdown-button');
let currentSeat = null;
let betDoubled = false;
let countdownInterval = null;
seats.forEach(seat => {
seat.addEventListener('click', () => {
console.log("Seat clicked:", seat);
if (seat.classList.contains('assigned')) {
const betElement = seat.querySelector('.bet');
const splitBetElement = seat.querySelector('.bet.split');
const betAmount = parseInt(betElement.textContent, 10);
if (betAmount > 0) {
currentSeat = seat;
if (splitBetElement) {
winLoseDialog.classList.remove('hidden');
winLoseDialogSecond.classList.remove('hidden');
} else {
winLoseDialog.classList.remove('hidden');
}
} else {
currentSeat = seat;
betDialog.classList.remove('hidden');
}
} else if (seat.classList.contains('dealer')) {
console.log("Dealer seat clicked");
currentSeat = seat; // Make sure currentSeat is set
dealerDialog.classList.remove('hidden');
console.log("Dealer dialog should be visible now");
} else {
currentSeat = seat;
assignDialog.classList.remove('hidden');
}
});
});
assignButton.addEventListener('click', () => {
const viewerName = viewerNameInput.value.trim();
if (viewerName && currentSeat) {
currentSeat.classList.add('assigned');
currentSeat.innerHTML = `${viewerName}<div class="balance" data-balance="1000">1000</div><div class="bet">0</div>`;
viewerNameInput.value = '';
assignDialog.classList.add('hidden');
}
});
placeBetButton.addEventListener('click', () => {
const betAmount = parseInt(betAmountInput.value.trim(), 10);
if (betAmount > 0 && currentSeat) {
const balanceElement = currentSeat.querySelector('.balance');
let currentBalance = parseInt(balanceElement.getAttribute('data-balance'), 10);
if (betAmount <= currentBalance) {
currentBalance -= betAmount;
balanceElement.setAttribute('data-balance', currentBalance);
balanceElement.textContent = currentBalance;
const betElement = currentSeat.querySelector('.bet');
betElement.textContent = betAmount;
// Remove split bet if it exists
const splitBetElement = currentSeat.querySelector('.bet.split');
if (splitBetElement) {
currentSeat.removeChild(splitBetElement);
}
betAmountInput.value = '';
betDialog.classList.add('hidden');
} else {
alert('Insufficient balance to place this bet.');
}
}
});
const handleResult = (result, betElement) => {
let betAmount = parseInt(betElement.textContent, 10);
if (betAmount > 0) {
const balanceElement = currentSeat.querySelector('.balance');
let currentBalance = parseInt(balanceElement.getAttribute('data-balance'), 10);
console.log(`Initial betAmount: ${betAmount}`);
console.log(`Initial currentBalance: ${currentBalance}`);
switch(result) {
case 'win':
currentBalance += betAmount * 2; // 1:1 payout
break;
case 'lose':
break;
case 'double':
if (!betDoubled) {
if (betAmount <= currentBalance) {
currentBalance -= betAmount;
betAmount *= 2;
console.log(`Doubled betAmount: ${betAmount}`);
console.log(`Updated currentBalance after doubling: ${currentBalance}`);
betElement.textContent = betAmount;
betDoubled = true;
} else {
alert('Insufficient balance to double the bet.');
}
}
break;
case 'push':
currentBalance += betAmount;
break;
case 'blackjack':
currentBalance += betAmount * 2.5; // 3:2 payout
break;
}
balanceElement.setAttribute('data-balance', currentBalance);
balanceElement.textContent = currentBalance;
console.log(`Updated balance: ${currentBalance}`);
if (result !== 'double') {
betElement.textContent = '0';
}
}
betDoubled = false;
}
winButton.addEventListener('click', () => {
handleResult('win', currentSeat.querySelector('.bet'));
winLoseDialog.classList.add('hidden');
});
loseButton.addEventListener('click', () => {
handleResult('lose', currentSeat.querySelector('.bet'));
winLoseDialog.classList.add('hidden');
});
doubleButton.addEventListener('click', () => {
handleResult('double', currentSeat.querySelector('.bet'));
});
pushButton.addEventListener('click', () => {
handleResult('push', currentSeat.querySelector('.bet'));
winLoseDialog.classList.add('hidden');
});
blackjackButton.addEventListener('click', () => {
handleResult('blackjack', currentSeat.querySelector('.bet'));
winLoseDialog.classList.add('hidden');
});
winButtonSecond.addEventListener('click', () => {
handleResult('win', currentSeat.querySelector('.bet.split'));
winLoseDialogSecond.classList.add('hidden');
});
loseButtonSecond.addEventListener('click', () => {
handleResult('lose', currentSeat.querySelector('.bet.split'));
winLoseDialogSecond.classList.add('hidden');
});
doubleButtonSecond.addEventListener('click', () => {
handleResult('double', currentSeat.querySelector('.bet.split'));
});
pushButtonSecond.addEventListener('click', () => {
handleResult('push', currentSeat.querySelector('.bet.split'));
winLoseDialogSecond.classList.add('hidden');
});
blackjackButtonSecond.addEventListener('click', () => {
handleResult('blackjack', currentSeat.querySelector('.bet.split'));
winLoseDialogSecond.classList.add('hidden');
});
closeButton.addEventListener('click', () => {
winLoseDialog.classList.add('hidden');
});
closeButtonSecond.addEventListener('click', () => {
winLoseDialogSecond.classList.add('hidden');
});
splitButton.addEventListener('click', () => {
const betElement = currentSeat.querySelector('.bet');
const betAmount = parseInt(betElement.textContent, 10);
if (betAmount > 0) {
const balanceElement = currentSeat.querySelector('.balance');
let currentBalance = parseInt(balanceElement.getAttribute('data-balance'), 10);
if (betAmount <= currentBalance) {
currentBalance -= betAmount;
balanceElement.setAttribute('data-balance', currentBalance);
balanceElement.textContent = currentBalance;
const splitBetElement = document.createElement('div');
splitBetElement.classList.add('bet', 'split');
splitBetElement.textContent = betAmount;
currentSeat.appendChild(splitBetElement);
winLoseDialog.classList.add('hidden'); // Close the result window on split
} else {
alert('Insufficient balance to split the bet.');
}
}
});
removePlayerButton.addEventListener('click', () => {
if (currentSeat) {
currentSeat.classList.remove('assigned');
currentSeat.classList.remove('dealer');
currentSeat.innerHTML = currentSeat.getAttribute('data-original-text');
currentSeat = null;
}
});
changeBalanceButton.addEventListener('click', () => {
if (currentSeat) {
changeBalanceDialog.classList.remove('hidden');
}
});
changeBalanceDoneButton.addEventListener('click', () => {
if (currentSeat) {
const newBalance = parseInt(newBalanceInput.value.trim(), 10);
if (!isNaN(newBalance) && newBalance >= 0) {
const balanceElement = currentSeat.querySelector('.balance');
balanceElement.setAttribute('data-balance', newBalance);
balanceElement.textContent = newBalance;
newBalanceInput.value = '';
changeBalanceDialog.classList.add('hidden');
} else {
alert('Please enter a valid balance amount.');
}
}
});
closeBetDialogButton.addEventListener('click', () => {
betDialog.classList.add('hidden');
});
confirmCountdownButton.addEventListener('click', () => {
const countdownSeconds = parseInt(countdownSecondsInput.value.trim(), 10);
if (!isNaN(countdownSeconds) && countdownSeconds > 0) {
if (countdownInterval) {
clearInterval(countdownInterval);
}
let remainingTime = countdownSeconds;
dealerDialog.classList.add('hidden'); // Close the dealer dialog
currentSeat.textContent = remainingTime; // Display the countdown in the dealer seat
countdownInterval = setInterval(() => {
remainingTime -= 1;
currentSeat.textContent = remainingTime;
if (remainingTime <= 0) {
clearInterval(countdownInterval);
currentSeat.textContent = 'Time\'s up!';
setTimeout(() => {
currentSeat.textContent = 'Dealer';
}, 2000); // Change text back to "Dealer" after 2 seconds
}
}, 1000);
} else {
alert('Please enter a valid number of seconds.');
}
});
});