-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
346 lines (305 loc) · 9.29 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
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
var carta1 = {
nome: "Elon Musk",
imagem:
"https://ted-conferences-speaker-photos-production.s3.amazonaws.com/c9bzt1ahc9iv09uth9oepbetmsuc",
atributos: {
creative: 5,
innovative: 9,
visionary: 8
}
};
var carta2 = {
nome: "Steve Jobs",
imagem:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTzEKY_9tW45XK-CTtt4kqogy1sb8wHn3-GGarIKtR87naROY90z9NSQwJzSdPKev-qpKw&usqp=CAU",
atributos: {
creative: 7,
visionary: 4,
innovative: 5
}
};
var carta3 = {
nome: "Bill Gates",
imagem:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT23Dx0SxHhzfpXijw-LCSKZLEx0ktL7wsPiaCgEx-oO0Df3rxt8-GZG-r1fzLWFIVc4K8&usqp=CAU",
atributos: {
creative: 8,
visionary: 5,
innovative: 4
}
};
var carta4 = {
nome: "Mark Zuckerberg",
imagem:
"https://www.suno.com.br/wp-content/uploads/2018/11/Mark-Zuckerberg-2.jpg",
atributos: {
creative: 7,
visionary: 7,
innovative: 8
}
};
var carta5 = {
nome: "Linus Torvalds",
imagem:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSfjV-kLn-RdVVIiX8E5GyPE_2P9SchxtxTow&usqp=CAU",
atributos: {
creative: 5,
visionary: 9,
innovative: 4
}
};
var carta6 = {
nome: "Nilkola Tesla",
imagem:
"https://upload.wikimedia.org/wikipedia/commons/thumb/7/79/Tesla_circa_1890.jpeg/460px-Tesla_circa_1890.jpeg",
atributos: {
creative: 4,
visionary: 4,
innovative: 8
}
};
var carta7 = {
nome: "Alan Cooper",
imagem:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQPrpySibpdUTbYA0WqBEmAQeO9g8z0CCLnqOhFBmbeNdfvfQjPmnqKGwZ5hH7zpZPJV0o&usqp=CAU",
atributos: {
creative: 5,
visionary: 10,
innovative: 7
}
};
var carta8 = {
nome: "Alonzo Church",
imagem:
"https://upload.wikimedia.org/wikipedia/en/a/a6/Alonzo_Church.jpg",
atributos: {
creative: 8,
visionary: 6,
innovative: 7
}
};
var carta9 = {
nome: "Richard Stallman",
imagem:
"https://usesthis.com/images/interviews/richard.stallman/portrait.jpg",
atributos: {
creative: 7,
visionary: 5,
innovative: 8
}
};
var carta10 = {
nome: "James Gosling",
imagem:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTkYzdcGbJsNbK9AzWEvVoWfVrWfwwRtqynTHpKEW8IxqP054KLfAIetyAfZEQKtwXRihQ&usqp=CAU",
atributos: {
creative: 4,
visionary: 8,
innovative: 4
}
};
var carta11 = {
nome: "Guido Van Rossum",
imagem: "https://gvanrossum.github.io/images/GuidoByPeterAdams.jpg",
atributos: {
creative: 3,
visionary: 5,
innovative: 5
}
};
var carta12 = {
nome: "Rasmus Lerdorf",
imagem:
"https://i.pinimg.com/474x/6d/e8/08/6de8084630cf02a5dbeb02a5e4c630c9--web-programming-languages-november-born.jpg",
atributos: {
creative: 6,
visionary: 4,
innovative: 7
}
};
var carta13 = {
nome: "Ada Lovelace",
imagem:
"https://www.ufrgs.br/enigma/wp-content/uploads/2021/02/https-_dynaimage.cdn_.cnn_.com_cnn_x_357y_0w_539h_719c_crop_https3A2F2Fstamp.static.cnn_.io2F5bab86cf4db3d70020c01c3e2Fada2-e1613402491497.jpg",
atributos: {
creative: 7,
visionary: 5,
innovative: 5
}
};
var carta14 = {
nome: "Anders Hejlsberg ",
imagem:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSxDD3zQcwA9KlnEw7J_HyLHBPpdTGTRTYRBiWNqA0mi3tNDi-QuxqY4RnNMdHkyXUaMSc&usqp=CAU",
atributos: {
creative: 6,
visionary: 4,
innovative: 9
}
};
var carta15 = {
nome: "Grace Murray Hopper",
imagem:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTkJnlscWpWh4RFjHB5vjWG8WA8WKfumSCw0CJA_lyVx45a4JwvoA4skmvQQcYPSY5QUT0&usqp=CAU",
atributos: {
creative: 9,
visionary: 6,
innovative: 8
}
};
var carta16 = {
nome: "Dennis Ritchie",
imagem:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTIPiqr5kCRqggHfGNKFSxiwtSE0nGJQbUt2cL2wQnVXrWeVHgBgpuyZFS7lVrfePxQV3A&usqp=CAU",
atributos: {
creative: 5,
visionary: 6,
innovative: 7
}
};
var cartasDoJogador = [];
var cartasDaMaquina = [];
var cartaMaquina;
var cartaJogador;
var cartas = [
carta1,
carta2,
carta3,
carta4,
carta5,
carta6,
carta7,
carta8,
carta9,
carta10,
carta11,
carta12,
carta13,
carta14,
carta15,
carta16
];
// 0 1 2
function sortearCarta() {
var numeroCartaMaquina = parseInt(Math.random() * 16);
cartaMaquina = cartas[numeroCartaMaquina];
var numeroCartaJogador = parseInt(Math.random() * 16);
while (numeroCartaJogador == numeroCartaMaquina) {
numeroCartaJogador = parseInt(Math.random() * 16);
}
cartaJogador = cartas[numeroCartaJogador];
console.log(cartaJogador);
document.getElementById("btnSortear").disabled = true;
document.getElementById("btnJogar").disabled = false;
exibirCartaJogador();
}
function obtemAtributoSelecionado() {
var radioAtributo = document.getElementsByName("atributo");
for (var i = 0; i < radioAtributo.length; i++) {
if (radioAtributo[i].checked) {
return radioAtributo[i].value;
}
}
}
function jogar() {
console.log("chamou");
var atributoSelecionado = obtemAtributoSelecionado();
var divResultado = document.getElementById("resultado");
if (
cartaJogador.atributos[atributoSelecionado] >
cartaMaquina.atributos[atributoSelecionado]
) {
htmlResultado = "<p class='resultado-final'>You Won!</p>";
cartasDoJogador.push(cartaMaquina);
} else if (
cartaJogador.atributos[atributoSelecionado] <
cartaMaquina.atributos[atributoSelecionado]
) {
htmlResultado = "<p class='resultado-final'>You Lost!</p>";
cartasDaMaquina.push(cartaJogador);
} else {
htmlResultado = "<p class='resultado-final'>Tied!</p>";
}
if (cartasDaMaquina.length == 5 || cartasDoJogador.length == 5) {
document.getElementById("btnJogar").disabled = true;
document.getElementById("btnProxima").disabled = true;
document.getElementById("btnSortear").disabled = true;
if (cartasDaMaquina.length == 5) {
htmlResultado = `<p class='resultado-final'> End of the game ! The winner was the machine by ${cartasDaMaquina.length} to ${cartasDoJogador.length}.</p>`;
document.getElementById("btnReiniciar").innerHTML =
"<button type='button' onclick='reiniciar()'>Restart</button>";
} else {
htmlResultado = `<p class='resultado-final'>End of the game ! The winner was you by ${cartasDoJogador.length} to ${cartasDaMaquina.length}.</p>`;
document.getElementById("btnReiniciar").innerHTML =
"<button type='button' onclick='reiniciar()'>Restart</button>";
}
} else {
document.getElementById("btnProxima").disabled = false;
}
divResultado.innerHTML = htmlResultado;
document.getElementById("btnJogar").disabled = true;
exibirCartaMaquina();
exibirPontuacao();
}
function exibirCartaJogador() {
var divCartaJogador = document.getElementById("carta-jogador");
divCartaJogador.innerHTML = `
<div class="card">
<img class="card-imagem" src="${cartaJogador.imagem}" alt="">
<div class="card-info">
<p class="info-titulo">${cartaJogador.nome}</p>
<div id="opcoes-jogador" class="opcoes"></div>
</div>
</div>
`;
var opcoes = document.getElementById("opcoes-jogador");
var opcoesTexto = "";
for (var atributo in cartaJogador.atributos) {
opcoesTexto += `<div class="atributo"><span><input type="radio" name="atributo" value="${atributo}" checked> ${atributo}</span><span>${cartaJogador.atributos[atributo]}</span></div>`;
}
opcoes.innerHTML = opcoesTexto;
}
function exibirCartaMaquina() {
var divCartaMaquina = document.getElementById("carta-maquina");
divCartaMaquina.innerHTML = `
<div class="card">
<img class="card-imagem" src="${cartaMaquina.imagem}" alt="">
<div class="card-info">
<p class="info-titulo">${cartaMaquina.nome}</p>
<div id="opcoes-maquina" class="opcoes"></div>
</div>
</div>
`;
var opcoes = document.getElementById("opcoes-maquina");
var opcoesTexto = "";
for (var atributo in cartaMaquina.atributos) {
opcoesTexto += `<div class="atributo"><span><p name="atributo">${atributo}</p></span><span>${cartaMaquina.atributos[atributo]}</span></div>`;
}
opcoes.innerHTML = opcoesTexto;
}
function proximaRodada() {
document.getElementById("btnSortear").disabled = false;
document.getElementById("btnProxima").disabled = true;
document.getElementById("resultado").innerHTML = "";
document.getElementById("carta-jogador").innerHTML = "";
document.getElementById("carta-maquina").innerHTML = "";
document.getElementById("carta-jogador").style.backgroundImage = "";
document.getElementById("carta-maquina").style.backgroundImage = "";
sortearCarta();
}
function exibirPontuacao() {
var pontuacao = document.getElementById("pontuacao");
pontuacao.innerHTML = `<span>Player- ${cartasDoJogador.length}</span> | <span>Machine - ${cartasDaMaquina.length}</span>`;
}
function reiniciar() {
document.getElementById("btnSortear").disabled = false;
document.getElementById("btnProxima").disabled = true;
document.getElementById("resultado").innerHTML = "";
document.getElementById("pontuacao").innerHTML = "";
document.getElementById("carta-jogador").innerHTML = "";
document.getElementById("carta-maquina").innerHTML = "";
document.getElementById("carta-jogador").style.backgroundImage = "";
document.getElementById("carta-maquina").style.backgroundImage = "";
cartasDaMaquina = [];
cartasDoJogador = [];
}