-
Notifications
You must be signed in to change notification settings - Fork 0
/
botoes.js
97 lines (83 loc) · 2.84 KB
/
botoes.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
// cancelar
btnCancelar.addEventListener("click", function() {
retornaPaginaInicial();
});
// novo jogo
btnNovoJogo.addEventListener("click", function() {
iniciaJogo();
document.addEventListener("keydown", escutaTeclado = (e) => {
var letra = e.key.toUpperCase();
var codigo = e.keyCode;
if((somenteLetras(codigo)) && (!verificarLetraCorreta(e.key))) {
if(palavraSecreta.includes(letra)){
adicionarLetraCorreta(palavraSecreta.indexOf(letra))
for(let i = 0; i < palavraSecreta.length; i++) {
if(palavraSecreta[i] === letra) {
escreverLetraCorreta(i);
letrasCorretas.push(letra);
verificaVitoria();
}
}
}
else if (!(palavraSecreta.includes(letra))){
adicionarLetraIncorreta(letra);
escreverLetraIncorreta(letra, erros);
desenhaEnforcado(erros);
}
}
});
});
// desistir
btnDesistir.addEventListener("click", function() {
retornaPaginaInicial();
});
// iniciar jogo na tela inicial
iniciaJogoBtn.addEventListener("click", function(){
iniciaJogo();
});
// adicionar palavra
adicionaPlavraBtn.addEventListener("click", function() {
telaInicial.classList.add("hide");
footer.classList.add("hide");
secaoInput.classList.remove("hide");
inputAddPalavra.focus();
paginaAtual = secaoInput;
});
// salvar palavra no input
btnSalvarPalavra.addEventListener("click", function() {
verificaPalavraDoInput();
});
btnSalvaInicia.addEventListener("click", function() {
limpaCanvas();
letras = [];
letrasCorretas = [];
palavraCorreta = "";
palavraSecreta = "";
erros = 6;
escreverTracinhos(escolherPalavraSecreta());
secaoInput.classList.add("hide");
footer.classList.add("hide");
secaoJogo.classList.remove("hide");
paginaAtual = secaoJogo;
document.addEventListener("keydown", escutaTeclado = (e) => {
var letra = e.key.toUpperCase();
var codigo = e.keyCode;
if((somenteLetras(codigo)) && (!verificarLetraCorreta(e.key))) {
if(palavraSecreta.includes(letra)){
adicionarLetraCorreta(palavraSecreta.indexOf(letra))
for(let i = 0; i < palavraSecreta.length; i++) {
if(palavraSecreta[i] === letra) {
escreverLetraCorreta(i);
letrasCorretas.push(letra);
verificaVitoria();
}
}
}
else if (!(palavraSecreta.includes(letra))){
adicionarLetraIncorreta(letra);
escreverLetraIncorreta(letra, erros);
desenhaEnforcado(erros);
}
}
});
});