forked from JohnnyBC2022/ZombiesDevGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.js
More file actions
52 lines (43 loc) · 1.45 KB
/
script2.js
File metadata and controls
52 lines (43 loc) · 1.45 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
document.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
const introStory2 = document.querySelector(".introStory2");
introStory2.style.display = "block";
const storyContent = document.querySelector(".storyContent");
storyContent.style.display = "none";
}
});
document.addEventListener("keydown", function (event) {
if (event.key === "ArrowLeft") {
redireccionar("./right-cards/intro1-right.html");
} else if (event.key === "ArrowRight") {
redireccionar("./wrong-cards/intro1-wrong.html");
}
});
function redireccionar(ruta) {
if (ruta === "./right-cards/intro1-right.html") {
const puntosActuales = obtenerPuntos();
guardarPuntos(puntosActuales);
} else if (ruta === "./wrong-cards/intro1-wrong.html") {
const puntosActuales = obtenerPuntos() - 200;
guardarPuntos(puntosActuales);
}
window.location.href = ruta;
}
function obtenerPuntos() {
return parseInt(localStorage.getItem("puntos"));
}
function guardarPuntos(puntos) {
localStorage.setItem("puntos", puntos);
}
const puntosActuales = obtenerPuntos();
const puntosElement = document.getElementById("points");
puntosElement.textContent = puntosActuales;
document.addEventListener("DOMContentLoaded", function () {
const resetButton = document.querySelector(".reset");
resetButton.addEventListener("click", function () {
reiniciarJuego();
});
});
function reiniciarJuego() {
window.location.href = "../index.html";
}