-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjogo_jogo.js
103 lines (87 loc) · 2.51 KB
/
jogo_jogo.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
var palavras = [
"PROGRAMADOR",
"JAVASCRIPT",
"CALCULADORA",
"ESTUDANTE",
"VSCODE",
"HTML",
"INTELIGENTE",
"ESCOLA",
"FACULDADE",
"CORRER",
"NOTEBOOK",
"COMPUTADOR",
"TEMPO",
"CELULAR",
"TABLET",
"DEVS",
"TECNOLOGIA",
]
let resposta = '';
let tentativas = 6;
let erros = 0;
let letraCorreta = [];
let verificaPalavra = null;
function sorteiaPalavra() {
resposta = palavras[Math.floor(Math.random() * palavras.length)];
}
function criarBotoes() {
let botoes = 'ABCDEFGHIJKLMNOPQRSTUVXWZ'.split('').map(letra =>
`
<button
class="btn btn-lg btn-dark m-1"
id='` + letra + `'
onClick="letraEscolhida('` + letra + `')"
>
` + letra + `
</button>
`).join('');
document.getElementById('keyboard').innerHTML = botoes;
}
function letraEscolhida(escolheLetra) {
letraCorreta.indexOf(escolheLetra) === -1 ? letraCorreta.push(escolheLetra) : null;
document.getElementById(escolheLetra).setAttribute('disabled', true);
if (resposta.indexOf(escolheLetra) >= 0) {
palavraCorreta();
verificaVitoria();
} else if (resposta.indexOf(escolheLetra) === -1) {
erros++;
atualizaErros();
verificaDerrota();
atualizaImage();
}
}
function atualizaImage() {
document.getElementById('jogoImage').src = 'madeira' + erros + '.png';
}
function verificaVitoria() {
if (verificaPalavra === resposta) {
document.getElementById('keyboard').innerHTML = 'Parabéns *_* Você Venceu!';
}
}
function verificaDerrota() {
if (erros === tentativas) {
document.getElementById('palavraVerificada').innerHTML = 'A Palavra Correta era: ' + resposta;
document.getElementById('keyboard').innerHTML = 'Você Perdeu -_- Tente Novamente!';
}
}
function palavraCorreta() {
verificaPalavra = resposta.split('').map(letra => (letraCorreta.indexOf(letra) >= 0 ? letra : " ___ ")).join('');
document.getElementById('palavraVerificada').innerHTML = verificaPalavra;
}
function atualizaErros() {
document.getElementById('erros').innerHTML = erros;
}
function reset() {
erros = 0;
letraCorreta = [];
document.getElementById('jogoImage').src = 'madeira.png';
sorteiaPalavra();
palavraCorreta();
atualizaErros();
criarBotoes();
}
document.getElementById('tentativas').innerHTML = tentativas;
sorteiaPalavra();
criarBotoes();
palavraCorreta();