Skip to content

Commit 70005a5

Browse files
committed
Agrega sonidos
1 parent 2fad1ad commit 70005a5

File tree

9 files changed

+62
-8
lines changed

9 files changed

+62
-8
lines changed

index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro&display=swap" rel="stylesheet">
88
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
99
<link rel="stylesheet" href="css/styles.css">
10-
<link href="img/favicon.ico" rel="icon" type="image/x-icon"/>
10+
<link href="img/favicon.ico" rel="icon" type="image/x-icon" />
1111
</head>
1212

1313
<body>
14+
<audio id="audio-uno" src="sounds/simonSound1.mp3"></audio>
15+
<audio id="audio-dos" src="sounds/simonSound2.mp3"></audio>
16+
<audio id="audio-tres" src="sounds/simonSound3.mp3"></audio>
17+
<audio id="audio-cuatro" src="sounds/simonSound4.mp3"></audio>
18+
<audio id="audio-start" src="sounds/start.wav"></audio>
19+
<audio id="audio-correct" src="sounds/correct.mp3"></audio>
20+
<audio id="audio-wrong" src="sounds/wrong.wav"></audio>
21+
1422
<form class="grid-container" id="form">
1523
<div class="sector1">
1624
<div class="puntaje">

js/main.js

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,41 @@ const $form = document.querySelector("#form")
22
let secuenciaPc = []
33
let turnoUser = false
44
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+
}
540

641
function permiteClickear() {
742
if (turnoUser === false) {
@@ -48,43 +83,47 @@ function eligeRandom() {
4883

4984
if (numerosRandoms[i] === eligeRojo) {
5085
setTimeout(function () {
86+
play1()
5187
nodoRojo.className = ('rojoActivado')
5288
}, tiempo)
5389
setTimeout(function () {
5490
nodoRojo.className = ('boton-rojo')
55-
}, tiempo + 400)
91+
}, tiempo + 500)
5692
}
5793

5894
if (numerosRandoms[i] === eligeVerde) {
5995
setTimeout(function () {
96+
play2()
6097
nodoVerde.className = ('verdeActivado')
6198
}, tiempo)
6299
setTimeout(function () {
63100
nodoVerde.className = ('boton-verde')
64-
}, tiempo + 400)
101+
}, tiempo + 500)
65102
}
66103

67104
if (numerosRandoms[i] === eligeAzul) {
68105
setTimeout(function () {
106+
play3()
69107
nodoAzul.className = ('azulActivado')
70108
}, tiempo)
71109
setTimeout(function () {
72110
nodoAzul.className = ('boton-azul')
73-
}, tiempo + 400)
111+
}, tiempo + 500)
74112
}
75113

76114
if (numerosRandoms[i] === eligeAmarillo) {
77115
setTimeout(function () {
116+
play4()
78117
nodoAmarillo.className = ('amarilloActivado')
79118
}, tiempo)
80119
setTimeout(function () {
81120
nodoAmarillo.className = ('boton-amarillo')
82-
}, tiempo + 400)
121+
}, tiempo + 500)
83122
}
84123

85124
setTimeout(function () {
86125
mostrarMensajeTurnoUser()
87-
}, tiempo + 400)
126+
}, tiempo + 500)
88127
turnos = 0
89128
}
90129
}
@@ -114,7 +153,7 @@ function asignarPuntajeMaximo() {
114153
}
115154
}
116155

117-
function gameOver(){
156+
function gameOver() {
118157
let nodoRojo = $form.querySelector("#rojo")
119158
let nodoVerde = $form.querySelector("#verde")
120159
let nodoAzul = $form.querySelector("#azul")
@@ -126,7 +165,7 @@ function gameOver(){
126165
nodoAmarillo.className = ('amarilloActivado')
127166
}
128167

129-
function gameStart(){
168+
function gameStart() {
130169
let nodoRojo = $form.querySelector("#rojo")
131170
let nodoVerde = $form.querySelector("#verde")
132171
let nodoAzul = $form.querySelector("#azul")
@@ -148,6 +187,7 @@ function turnoJugador(num) {
148187
if (turnos === secuenciaPc.length - 1) {
149188
nodoMensaje.value = 'Correcto!'
150189
nodoPuntaje.value = puntaje + 1
190+
playCorrect()
151191
asignarPuntajeMaximo()
152192
turnoPc()
153193
} else {
@@ -159,13 +199,15 @@ function turnoJugador(num) {
159199
if (num != secuenciaPc[turnos]) {
160200
noPermiteClickear()
161201
nodoMensaje.value = 'Incorrecto! Vuelve a empezar'
202+
playWrong()
162203
gameOver()
163204
asignarPuntajeMaximo()
164205
return ''
165206
}
166207
}
167208

168209
$form.start.onclick = function () {
210+
playStart()
169211
gameStart()
170212
noPermiteClickear()
171213
puntaje.value = 0
@@ -176,6 +218,7 @@ $form.start.onclick = function () {
176218
}
177219

178220
$form.querySelector("#rojo").onclick = function (event) {
221+
play1()
179222
if (turnoUser === true) {
180223
turnoJugador(1)
181224
event.preventDefault()
@@ -185,6 +228,7 @@ $form.querySelector("#rojo").onclick = function (event) {
185228
}
186229

187230
$form.querySelector("#verde").onclick = function (event) {
231+
play2()
188232
if (turnoUser === true) {
189233
turnoJugador(2)
190234
event.preventDefault()
@@ -194,6 +238,7 @@ $form.querySelector("#verde").onclick = function (event) {
194238
}
195239

196240
$form.querySelector("#azul").onclick = function (event) {
241+
play3()
197242
if (turnoUser === true) {
198243
turnoJugador(3)
199244
event.preventDefault()
@@ -203,6 +248,7 @@ $form.querySelector("#azul").onclick = function (event) {
203248
}
204249

205250
$form.querySelector("#amarillo").onclick = function (event) {
251+
play4()
206252
if (turnoUser === true) {
207253
turnoJugador(4)
208254
event.preventDefault()

sounds/correct.mp3

18.4 KB
Binary file not shown.

sounds/simonSound1.mp3

1.63 KB
Binary file not shown.

sounds/simonSound2.mp3

1.23 KB
Binary file not shown.

sounds/simonSound3.mp3

1.28 KB
Binary file not shown.

sounds/simonSound4.mp3

1.02 KB
Binary file not shown.

sounds/start.wav

42 KB
Binary file not shown.

sounds/wrong.wav

34.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)