-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
373 lines (311 loc) · 14.1 KB
/
main.js
File metadata and controls
373 lines (311 loc) · 14.1 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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
//nicknames
let nick1;
let nick2;
//posições jogadores
let posicaoPlay1 = '1';
let posicaoPlay2 = '2';
let casaPlay1 = 0;
let casaPlay2 = 0;
//casa que foi curado
let casaCurada1;
let casaCurada2;
//antídotos
let antidotoPlay1 = 3;
let antidotoPlay2 = 3;
//dados
let dado1;
let dado2;
let somaDados;
//construção do tabuleiro
let tabuleiro = [];
let armadilha;
let id = 1;
let rodadas = 1;
//jogar o jogo
function jogar() {
//coletando os nicknames dos jogadores
nick1 = document.getElementById("nick1").value;
nick2 = document.getElementById("nick2").value;
//altera o que aparece na página
document.getElementById("nicknames").style.display = "none";
//inserindo o tabuleiro
document.getElementById("tabela").innerHTML =
`<tr id='linha'>
<td style="background: rgb(116, 163, 116)" id="inicio1">1</td>
</tr>
<tr>
<td style="background: rgb(122, 64, 122)" id="inicio2">2</td>
</tr>`;
//sorteando as casas da armadilha
for (i = 0; i < 10; i++) {
armadilha = Math.floor(Math.random() * 30);
//verifica se a armadilha sorteada já é uma armadilha
while (tabuleiro[armadilha] == -1) {
armadilha = Math.floor(Math.random() * 30);
}
tabuleiro[armadilha] = -1;
}
//preenchendo as casas restantes do tabuleiro
for (let i = 0; i < 30; i++) {
if (tabuleiro[i] != -1) {
tabuleiro[i] = 0;
}
document.getElementById("linha").innerHTML += `<td rowspan="2" id="${id}">${tabuleiro[i]}</td>`;
id++;
}
document.getElementById("linha").innerHTML += `<td rowspan="2" id="chegada">ARRIVAL</td>`;
document.getElementById("jogo").style.display = "flex";
document.getElementById("player").innerText = `${nick1}, make your choice`;
document.getElementById("extra1").innerText = `${nick1}`;
document.getElementById("extra2").innerText = `${nick2}`;
}
//rolar dados
function rolarDados() {
//verifica quem está jogando
if (rodadas % 2 != 0) {
if (tabuleiro[casaPlay1 - 1] == -1) {
curarVeneno();
} else {
avancarCasas();
//recoloca o -1 no elemento do vetor original
tabuleiro[casaCurada1 - 1] = -1;
//recoloca a armadilha na tela
document.getElementById(casaCurada1).innerHTML = tabuleiro[casaCurada1 - 1];
}
} else {
if (tabuleiro[casaPlay2 - 1] == -1) {
curarVeneno();
} else {
avancarCasas();
//recoloca o -1 no elemento do vetor original
tabuleiro[casaCurada2 - 1] = -1;
//recoloca a armadilha na tela
document.getElementById(casaCurada2).innerHTML = tabuleiro[casaCurada2 - 1];
}
}
}
//rolar dados p/ andar
function avancarCasas() {
//sorteio de dados
dado1 = Math.floor(Math.random() * 6 + 1);
dado2 = Math.floor(Math.random() * 6 + 1);
somaDados = dado1 + dado2;
//cada rodada
if (rodadas % 2 != 0) {
document.getElementById("player").innerText = `${nick2}, make your choice`;
//atualiza os status do jogo
document.getElementById("status").innerHTML =
`Dice 1 = ${dado1} <br> Dice 2 = ${dado2}
<br><br> ${nick1} will walk ${somaDados} houses`;
//retornar a casa antiga para o valor do início
if (rodadas != 1) {
document.getElementById(casaPlay1).innerText = tabuleiro[casaPlay1 - 1];
document.getElementById(casaPlay1).style.backgroundColor = 'white';
}
//casa nova
casaPlay1 += somaDados;
//se for igual, volta 1 casa
if (casaPlay1 == casaPlay2) {
casaPlay1 = casaPlay1 - 1;
} else {
casaPlay1 = casaPlay1;
}
//verifica se alguém chegou ao fim do jogo
if (casaPlay1 > 30) {
document.getElementById('casa1').innerHTML = `is in the arrival house`;
document.getElementById('chegada').innerHTML = `${nick1} WON`;
document.getElementById('chegada').style.backgroundColor = 'rgb(116, 163, 116)';
document.getElementById('status').innerHTML = `${nick1} won`;
document.getElementById("player").innerText = `FINISHED`;
document.getElementById("botRolar").disabled = true;
document.getElementById("botRolar").style.cursor = 'default';
document.getElementById("botTomar").disabled = true;
document.getElementById("botTomar").style.cursor = 'default';
document.getElementById("botDesistir").disabled = true;
document.getElementById("botDesistir").style.cursor = 'default';
}
//atualiza a posição do jog na tela com sua cor
document.getElementById(casaPlay1).innerText = posicaoPlay1;
document.getElementById(casaPlay1).style.backgroundColor = 'rgb(116, 163, 116)';
document.getElementById('casa1').innerHTML = `Is in the house ${casaPlay1}`;
document.getElementById("inicio1").innerHTML = `BEGIN`;
document.getElementById("inicio1").style.backgroundColor = 'white';
//verifica se caiu na armadilha
if (tabuleiro[casaPlay1 - 1] == -1) {
document.getElementById('status').innerHTML += `<br> ${nick1} fell into the trap`;
}
} else {
document.getElementById("player").innerText = `${nick1}, make your choice`;
//atualiza os status do jogo
document.getElementById("status").innerHTML =
`Dice 1 = ${dado1} <br> Dice 2 = ${dado2}
<br><br> ${nick2} will walk ${somaDados} houses`;
//retornar a casa antiga para o valor do início
if (rodadas != 2) {
document.getElementById(casaPlay2).innerText = tabuleiro[casaPlay2 - 1];
document.getElementById(casaPlay2).style.backgroundColor = 'white';
}
//casa nova
casaPlay2 += somaDados;
//se for igual, volta 1 casa
if (casaPlay2 == casaPlay1) {
casaPlay2 = casaPlay2 - 1;
} else {
casaPlay2 = casaPlay2;
}
//verifica se alguém chegou ao fim do jogo
if (casaPlay2 > 30) {
document.getElementById('casa2').innerHTML = `is in the arrival house`;
document.getElementById('chegada').innerHTML = `${nick2} WON`;
document.getElementById('chegada').style.backgroundColor = 'rgb(122, 64, 122)';
document.getElementById('status').innerHTML = `${nick2} won`;
document.getElementById("player").innerText = `FINISHED`;
document.getElementById("botRolar").disabled = true;
document.getElementById("botRolar").style.cursor = 'default';
document.getElementById("botTomar").disabled = true;
document.getElementById("botTomar").style.cursor = 'default';
document.getElementById("botDesistir").disabled = true;
document.getElementById("botDesistir").style.cursor = 'default';
}
//atualiza a posição do jog na tela com sua cor
document.getElementById(casaPlay2).innerText = posicaoPlay2;
document.getElementById(casaPlay2).style.backgroundColor = 'rgb(122, 64, 122)';
document.getElementById('casa2').innerHTML = `Is in the house ${casaPlay2}`;
document.getElementById("inicio2").innerHTML = `NING`;
document.getElementById("inicio2").style.backgroundColor = 'white';
//verifica se caiu na armadilha
if (tabuleiro[casaPlay2 - 1] == -1) {
document.getElementById('status').innerHTML += `<br> ${nick2} fell into the trap`;
}
}
//atualiza a rodada
rodadas++;
}
//rolar dados envenenado
function curarVeneno() {
//sorteia os dados
dado1 = Math.floor(Math.random() * 6 + 1);
dado2 = Math.floor(Math.random() * 6 + 1);
document.getElementById("status").innerHTML =
`Dice 1 = ${dado1} <br> Dice 2 = ${dado2}
<br>`;
if (rodadas % 2 != 0) {
//verifica se são iguais
if (dado1 == dado2) {
document.getElementById('status').innerHTML += `<br> The dices are the same!
<br> ${nick1} is cured of the poison!`;
//pega a casa que foi curada
casaCurada1 = casaPlay1;
//muda o valor do elemento do vetor tabuleiro p/ jog andar na próx rodada
tabuleiro[casaPlay1 - 1] = 0;
} else {
//muda a casa antiga pra branco
document.getElementById(casaPlay1).innerText = String(tabuleiro[casaPlay1 - 1]);
document.getElementById(casaPlay1).style.backgroundColor = 'white';
//atualiza a casa nova
casaPlay1 = casaPlay1 - 2
//se cair na mesma casa que o outro player, volta mais 3 casas
if (casaPlay1 == casaPlay2) {
document.getElementById('status').innerHTML += `<br> ${nick1} will have to go back 5 houses`;
casaPlay1 = casaPlay1 - 3
document.getElementById(casaPlay1).innerText = posicaoPlay1;
document.getElementById(casaPlay1).style.backgroundColor = 'rgb(116, 163, 116)';
document.getElementById('casa1').innerHTML = `Is in the house ${casaPlay1}`;
} else {
document.getElementById('status').innerHTML += `<br> ${nick1} will have to go back 2 houses`;
document.getElementById(casaPlay1).innerText = posicaoPlay1;
document.getElementById(casaPlay1).style.backgroundColor = 'rgb(116, 163, 116)';
document.getElementById('casa1').innerHTML = `Is in the house ${casaPlay1}`;
}
//vê se caiu novamente em uma armadilha
if (tabuleiro[casaPlay1 - 1] == -1) {
document.getElementById('status').innerHTML += `<br> ${nick1} fell into the trap`;
}
}
document.getElementById("player").innerText = `${nick2}, make your choice`;
rodadas++;
} else {
//verifica se são iguais
if (dado1 == dado2) {
document.getElementById('status').innerHTML += `<br> The dices are the same!
<br> ${nick2} is cured of the poison`;
//pega a casa que foi curada
casaCurada2 = casaPlay2;
//muda o valor do elemento do vetor tabuleiro p/ jog andar na próx rodada
tabuleiro[casaPlay2 - 1] = 0;
} else {
//muda a casa antiga pra branco
document.getElementById(casaPlay2).innerText = String(tabuleiro[casaPlay2 - 1]);
document.getElementById(casaPlay2).style.backgroundColor = 'white';
//atualiza a casa nova
casaPlay2 = casaPlay2 - 2
//se cair na mesma casa que o outro player, volta mais 3 casas
if (casaPlay2 == casaPlay1) {
document.getElementById('status').innerHTML += `<br> ${nick2} will have to go back 5 houses`;
casaPlay2 = casaPlay1 - 3
document.getElementById(casaPlay2).innerText = posicaoPlay2;
document.getElementById(casaPlay2).style.backgroundColor = 'rgb(122, 64, 122)';
document.getElementById('casa2').innerHTML = `Is in the house ${casaPlay2}`;
} else {
document.getElementById('status').innerHTML += `<br> ${nick2} will have to go back 2 houses`;
document.getElementById(casaPlay2).innerText = posicaoPlay2;
document.getElementById(casaPlay2).style.backgroundColor = 'rgb(122, 64, 122)';
document.getElementById('casa2').innerHTML = `Is in the house ${casaPlay2}`;
}
//vê se caiu novamente em uma armadilha
if (tabuleiro[casaPlay2 - 1] == -1) {
document.getElementById('status').innerHTML += `<br> ${nick2} fell into the trap`;
}
}
document.getElementById("player").innerText = `${nick1}, make your choice`;
rodadas++;
}
}
//tomar antídoto
function tomarAntidoto() {
if (rodadas % 2 != 0) {
if (antidotoPlay1 == 0) {
document.getElementById('status').innerHTML = `${nick1} has no more antidotes`;
} else {
antidotoPlay1--;
document.getElementById('status').innerHTML = `${nick1} took an antidote and <br> is cured of the poison`;
document.getElementById('estoque1').innerHTML = `Antidotes: ${antidotoPlay1}`;
//pega a casa que foi tomado o antídoto
casaCurada1 = casaPlay1;
//muda o valor do elemento do vetor tabuleiro p/ jog andar na próx rodada
tabuleiro[casaPlay1 - 1] = 0;
}
} else {
if (antidotoPlay2 == 0) {
document.getElementById('status').innerHTML = `${nick2} has no more antidotes`;
} else {
antidotoPlay2--;
document.getElementById('status').innerHTML = `${nick2} took an antidote and <br> is cured of the poison`;
document.getElementById('estoque2').innerHTML = `Antidotes: ${antidotoPlay2}`;
//pega a casa que foi tomado o antídoto
casaCurada2 = casaPlay2;
//muda o valor do elemento do vetor tabuleiro p/ jog andar na próx rodada
tabuleiro[casaPlay2 - 1] = 0;
}
}
rodadas++;
}
//desistir
function desistir() {
if (rodadas % 2 != 0) {
document.getElementById('status').innerHTML = `${nick1} gave up`;
document.getElementById('casa1').innerHTML = `Quit the game`;
document.getElementById('status').innerHTML += `<br><br>${nick2} won`;
} else {
document.getElementById('status').innerHTML = `${nick2} gave up`;
document.getElementById('casa2').innerHTML = `Quit the game`;
document.getElementById('status').innerHTML += `<br><br>${nick1} won`;
}
document.getElementById("player").innerText = `FINISHED`;
document.getElementById("botRolar").disabled = true;
document.getElementById("botRolar").style.cursor = 'default';
document.getElementById("botTomar").disabled = true;
document.getElementById("botTomar").style.cursor = 'default';
document.getElementById("botDesistir").disabled = true;
document.getElementById("botDesistir").style.cursor = 'default';
}