-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnerdo_script.js
118 lines (104 loc) · 3.05 KB
/
nerdo_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
const explanation = document.getElementById("explanation");
const btnEasy = document.getElementById("btnEasy");
const btnMedium = document.getElementById("btnMedium");
const btnHard = document.getElementById("btnHard");
const btnStartGame = document.getElementById("btnStartGame");
const btnSkipRiddle = document.getElementById("btnSkipRiddle");
const btnRestart = document.getElementById("btnRestart");
let randomWord;
let randomWordHidden;
const clueOnHtml = document.getElementById("clueOnHtml");
const divLetterInput = document.getElementById("divLetterInput");
let attempt = 0;
const attemptOnHtml = document.getElementById("attempt");
const wrongLettersOnHtml = document.getElementById("wrongLetters");
let failedLetters = [];
let enteredLetter = document.getElementById("letterInput");
let guessedWord;
const gameScore = document.getElementById("gameScore");
const highScore = document.getElementById("highScore");
let actualScore = 0;
let highestScore;
const penalty = 50;
let interval;
const music = document.getElementById("music");
music.volume = 0.05;
const musicOnOff = document.getElementById("musicOnOff");
const volumeOn = document.getElementById("volumeOn");
const volumeOff = document.getElementById("volumeOff");
//*ARRAY DE PALABRAS PARA ADIVINAR
let riddlesArray = [];
//* ARRAY DE INDICES LANZADOS ALEATORIAMENTE
let indexArray = [];
//* ARRAY DE INDICES DE PALABRAS ADIVINADAS
let guessedArray = [];
//*ARRAY NERDO, SI LO COMPLETAS SOS THE REAL NERDO
let nerdoArray = [1];
btnEasy.onclick = () => {
loadRiddlesEasy().then((data) => {
riddlesArray = data;
});
btnStartGame.classList.remove("d-none");
changeBtnColorEasy();
adviceOfInputs();
};
btnMedium.onclick = () => {
loadRiddlesMedium().then((data) => {
riddlesArray = data;
});
btnStartGame.classList.remove("d-none");
changeBtnColorMedium();
adviceOfInputs();
};
btnHard.onclick = () => {
loadRiddlesHard().then((data) => {
riddlesArray = data;
});
btnStartGame.classList.remove("d-none");
changeBtnColorHard();
adviceOfInputs();
};
btnRestart.onclick = () => {
location.reload();
};
btnStartGame.onclick = () => {
if (playerWins()) {
resetGame();
} else {
checkHighScoreInStorage();
resetFailedLettersAndPenalty();
initializeIndexArray(riddlesArray.length);
shuffle(indexArray);
hideRandomWord(pickRandomWord(riddlesArray));
showClueScoreAttemptsBtns();
if (guessedArray.length >= 1) {
applyPenalty();
}
}
};
divLetterInput.onchange = () => {
checkLetterReplaceHyphen(enteredLetterToUpperCase());
showClueAndHiddenWord();
if (playerGuessedWord()) {
removeGuessedWord();
addGuessedToNerdoArray();
} else {
playerFails();
}
if (attempt === 5) {
playerLoose();
}
};
btnSkipRiddle.onclick = () => {
penaltyForSkippingRiddle();
if (playerWins()) {
resetGame();
} else {
checkHighScoreInStorage();
resetFailedLettersAndPenalty();
initializeIndexArray(riddlesArray.length);
shuffle(indexArray);
hideRandomWord(pickRandomWord(riddlesArray));
showClueScoreAttemptsBtns();
}
};