-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunion.js
205 lines (170 loc) · 5.97 KB
/
union.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
let moves = 0;
let showmoves = document.getElementById("moves");
let hits = 0;
let showhits = document.getElementById("hits");
let time = false;
let timer = 0;
let timeInitial = 0;
let showtime = document.getElementById("tiempo");
let sound = new Audio("./sound/click boton.wav");
let soundfail = new Audio("./sound/sound (fallo.wav");
let soundgood = new Audio("./sound/sound acierto.wav");
let winAudio = new Audio("./sound/sound ganar.wav");
let loseAudio = new Audio("./sound/sound perder.wav");
//generar numeros aleatorios//
let numbers = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8];
numbers = numbers.sort(() => {
return Math.random() - 0.5;
});
console.log(numbers);
//funcion del cambio//
let cardsturn = 0;
let card1 = null;
let card2 = null;
let firstresult = null;
let secondresult = null;
let timestop = null;
//contar tiempo
function counttime() {
timestop = setInterval(() => {
timer++;
showtime.innerHTML = `Time: ${timer} seconds`;
if (timer === 77) {
clearInterval(timestop);
lockCard();
let timeDurationVar = timer - timeInitial;
localStorage.setItem("timestop", timeDurationVar);
let showtimefinish = document.getElementById("time");
loseAudio.play();
let papafinalwin = document.getElementById("papafinal");
papafinalwin.classList.remove("finish5");
let tarjetafinal = document.getElementById("main-body");
tarjetafinal.classList.add("finish5");
showtimefinish.innerHTML = timeInitial - timer;
let showtimeWin = document.getElementById("tiempo-lost");
showtimeWin.innerHTML = localStorage.getItem("timestop");
}
}, 1400);
}
/* Oculta imagenes , funcion que se llama en el listener LINEA 186,187,188 */
function hideCards() {
for (let i = 0; i <= 15; i++) {
let tarjetabloqueada = document.getElementById(i);
tarjetabloqueada.innerHTML = "";
}
}
function lockCard() {
for (let i = 0; i <= 15; i++) {
let tarjetabloqueada = document.getElementById(i);
tarjetabloqueada.innerHTML = `<img src="./assets/${numbers[i]}.jpg" alt="">`;
tarjetabloqueada.disabled = false;
}
}
function turn(id) {
if (time === false) {
counttime();
time = true;
}
cardsturn++;
console.log(cardsturn);
if (cardsturn === 1) {
card1 = document.getElementById(id);
firstresult = numbers[id];
card1.innerHTML = `<img src="./assets/${firstresult}.jpg" alt="">`;
sound.play();
//deshabilitar el primerboton//
card1.disabled = true;
} else if (cardsturn === 2) {
//mostras segund numero//
card2 = document.getElementById(id);
secondresult = numbers[id];
card2.innerHTML = `<img src="./assets/${secondresult}.jpg" alt="">`;
//deshabilitar el segundo//
card2.disabled = true;
//movimientos//
moves++;
showmoves.innerHTML = `Moves: ${moves}`; //estp//
if (firstresult === secondresult) {
cardsturn = 0;
//aciertos//
hits++;
showhits.innerHTML = `Hits: ${hits}`; //estp//
soundgood.play();
if (hits === 8) {
winAudio.play();
clearInterval(timestop);
let timeDurationVar = timer - timeInitial;
localStorage.setItem("timestop", timeDurationVar);
let timeDuration = localStorage.getItem("timestop");
showhits.innerHTML = `Hits: ${hits} hits`;
showtime.innerHTML = `Your time: ${timeDuration} seconds`;
showmoves.innerHTML = `Moves: ${moves} <Equipo Turing😁>`;
let showtimeWin = document.getElementById("tiempo-win");
showtimeWin.innerHTML = localStorage.getItem("timestop");
let showtimefinish = document.getElementById("time");
showtimefinish.innerHTML = timeDuration;
let papafinalwin = document.getElementById("main-bodyfinish");
papafinalwin.classList.remove("finish5");
let tarjetafinal = document.getElementById("main-body");
tarjetafinal.classList.add("finish5");
}
} else {
soundfail.play();
//mostrar valores de forma mometanea//
setTimeout(() => {
card1.innerHTML = " ";
card2.innerHTML = " ";
card1.disabled = false;
card2.disabled = false;
cardsturn = 0;
}, 500);
}
}
}
let primerName = document.getElementById("name");
let namePlayer = localStorage.getItem("players");
primerName.textContent = namePlayer;
document.addEventListener("DOMContentLoaded", () => {
let primerName = document.getElementById("name");
let nameScore = document.getElementById("name-score");
let btnStart = document.getElementById("btn-start");
btnStart.addEventListener("click", (e) => {
// let mainBody = document.querySelector(".main-dad");
let name = document.getElementById("nombre-user").value;
localStorage.setItem("players", name);
localStorage.setItem("scoring", name);
// window.location.reload();
// mainBody.style.display = "none";
let bodyStart = document.querySelector("#user-zonePrincipal");
bodyStart.classList.add("finish5");
let bodyCard = document.querySelector("#main-body");
bodyCard.classList.remove("finish5");
e.preventDefault();
let namePlayer = localStorage.getItem("players");
primerName.textContent = namePlayer;
nameScore.textContent = namePlayer;
let actualPlayer = document.getElementById("actual-player-info");
actualPlayer.textContent = `${namePlayer} is currently playing`;
/* Muestra las imagenes */
function lockCarad() {
for (let i = 0; i <= 15; i++) {
let tarjetabloqueada = document.getElementById(i);
tarjetabloqueada.innerHTML = `<img src="./assets/${numbers[i]}.jpg" alt="">`;
}
}
lockCarad();
/* Oculta imagenes tras 3 segundos */
setTimeout(() => {
hideCards();
}, 1377);
});
let btnWon = document.getElementById("btn-play-win");
let btnLost = document.getElementById("btn-play-lost");
btnWon.addEventListener("click", () => {
window.location.reload();
});
btnLost.addEventListener("click", () => {
window.location.reload();
});
});
//finish