@@ -2,6 +2,41 @@ const $form = document.querySelector("#form")
2
2
let secuenciaPc = [ ]
3
3
let turnoUser = false
4
4
let turnos = 0
5
+ let sonidoUno = document . querySelector ( "#audio-uno" )
6
+ let sonidoDos = document . querySelector ( "#audio-dos" )
7
+ let sonidoTres = document . querySelector ( "#audio-tres" )
8
+ let sonidCuatro = document . querySelector ( "#audio-cuatro" )
9
+ let sonidoCorrect = document . querySelector ( "#audio-correct" )
10
+ let sonidoWrong = document . querySelector ( "#audio-wrong" )
11
+ let sonidoStart = document . querySelector ( "#audio-start" )
12
+
13
+ function play1 ( ) {
14
+ sonidoUno . play ( ) ;
15
+ }
16
+
17
+ function play2 ( ) {
18
+ sonidoDos . play ( ) ;
19
+ }
20
+
21
+ function play3 ( ) {
22
+ sonidoTres . play ( ) ;
23
+ }
24
+
25
+ function play4 ( ) {
26
+ sonidoCuatro . play ( ) ;
27
+ }
28
+
29
+ function playStart ( ) {
30
+ sonidoStart . play ( ) ;
31
+ }
32
+
33
+ function playCorrect ( ) {
34
+ sonidoCorrect . play ( ) ;
35
+ }
36
+
37
+ function playWrong ( ) {
38
+ sonidoWrong . play ( ) ;
39
+ }
5
40
6
41
function permiteClickear ( ) {
7
42
if ( turnoUser === false ) {
@@ -48,43 +83,47 @@ function eligeRandom() {
48
83
49
84
if ( numerosRandoms [ i ] === eligeRojo ) {
50
85
setTimeout ( function ( ) {
86
+ play1 ( )
51
87
nodoRojo . className = ( 'rojoActivado' )
52
88
} , tiempo )
53
89
setTimeout ( function ( ) {
54
90
nodoRojo . className = ( 'boton-rojo' )
55
- } , tiempo + 400 )
91
+ } , tiempo + 500 )
56
92
}
57
93
58
94
if ( numerosRandoms [ i ] === eligeVerde ) {
59
95
setTimeout ( function ( ) {
96
+ play2 ( )
60
97
nodoVerde . className = ( 'verdeActivado' )
61
98
} , tiempo )
62
99
setTimeout ( function ( ) {
63
100
nodoVerde . className = ( 'boton-verde' )
64
- } , tiempo + 400 )
101
+ } , tiempo + 500 )
65
102
}
66
103
67
104
if ( numerosRandoms [ i ] === eligeAzul ) {
68
105
setTimeout ( function ( ) {
106
+ play3 ( )
69
107
nodoAzul . className = ( 'azulActivado' )
70
108
} , tiempo )
71
109
setTimeout ( function ( ) {
72
110
nodoAzul . className = ( 'boton-azul' )
73
- } , tiempo + 400 )
111
+ } , tiempo + 500 )
74
112
}
75
113
76
114
if ( numerosRandoms [ i ] === eligeAmarillo ) {
77
115
setTimeout ( function ( ) {
116
+ play4 ( )
78
117
nodoAmarillo . className = ( 'amarilloActivado' )
79
118
} , tiempo )
80
119
setTimeout ( function ( ) {
81
120
nodoAmarillo . className = ( 'boton-amarillo' )
82
- } , tiempo + 400 )
121
+ } , tiempo + 500 )
83
122
}
84
123
85
124
setTimeout ( function ( ) {
86
125
mostrarMensajeTurnoUser ( )
87
- } , tiempo + 400 )
126
+ } , tiempo + 500 )
88
127
turnos = 0
89
128
}
90
129
}
@@ -114,7 +153,7 @@ function asignarPuntajeMaximo() {
114
153
}
115
154
}
116
155
117
- function gameOver ( ) {
156
+ function gameOver ( ) {
118
157
let nodoRojo = $form . querySelector ( "#rojo" )
119
158
let nodoVerde = $form . querySelector ( "#verde" )
120
159
let nodoAzul = $form . querySelector ( "#azul" )
@@ -126,7 +165,7 @@ function gameOver(){
126
165
nodoAmarillo . className = ( 'amarilloActivado' )
127
166
}
128
167
129
- function gameStart ( ) {
168
+ function gameStart ( ) {
130
169
let nodoRojo = $form . querySelector ( "#rojo" )
131
170
let nodoVerde = $form . querySelector ( "#verde" )
132
171
let nodoAzul = $form . querySelector ( "#azul" )
@@ -148,6 +187,7 @@ function turnoJugador(num) {
148
187
if ( turnos === secuenciaPc . length - 1 ) {
149
188
nodoMensaje . value = 'Correcto!'
150
189
nodoPuntaje . value = puntaje + 1
190
+ playCorrect ( )
151
191
asignarPuntajeMaximo ( )
152
192
turnoPc ( )
153
193
} else {
@@ -159,13 +199,15 @@ function turnoJugador(num) {
159
199
if ( num != secuenciaPc [ turnos ] ) {
160
200
noPermiteClickear ( )
161
201
nodoMensaje . value = 'Incorrecto! Vuelve a empezar'
202
+ playWrong ( )
162
203
gameOver ( )
163
204
asignarPuntajeMaximo ( )
164
205
return ''
165
206
}
166
207
}
167
208
168
209
$form . start . onclick = function ( ) {
210
+ playStart ( )
169
211
gameStart ( )
170
212
noPermiteClickear ( )
171
213
puntaje . value = 0
@@ -176,6 +218,7 @@ $form.start.onclick = function () {
176
218
}
177
219
178
220
$form . querySelector ( "#rojo" ) . onclick = function ( event ) {
221
+ play1 ( )
179
222
if ( turnoUser === true ) {
180
223
turnoJugador ( 1 )
181
224
event . preventDefault ( )
@@ -185,6 +228,7 @@ $form.querySelector("#rojo").onclick = function (event) {
185
228
}
186
229
187
230
$form . querySelector ( "#verde" ) . onclick = function ( event ) {
231
+ play2 ( )
188
232
if ( turnoUser === true ) {
189
233
turnoJugador ( 2 )
190
234
event . preventDefault ( )
@@ -194,6 +238,7 @@ $form.querySelector("#verde").onclick = function (event) {
194
238
}
195
239
196
240
$form . querySelector ( "#azul" ) . onclick = function ( event ) {
241
+ play3 ( )
197
242
if ( turnoUser === true ) {
198
243
turnoJugador ( 3 )
199
244
event . preventDefault ( )
@@ -203,6 +248,7 @@ $form.querySelector("#azul").onclick = function (event) {
203
248
}
204
249
205
250
$form . querySelector ( "#amarillo" ) . onclick = function ( event ) {
251
+ play4 ( )
206
252
if ( turnoUser === true ) {
207
253
turnoJugador ( 4 )
208
254
event . preventDefault ( )
0 commit comments