Skip to content

Commit 2c29d4f

Browse files
committed
🎨 Update
1 parent 995ce65 commit 2c29d4f

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

script.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,48 @@ class Juego {
107107
this.nivel++;
108108
this.eliminarEventosClick();
109109
if (this.nivel === ULTIMO_NIVEL + 1) {
110-
// Ganó!
110+
this.winGame();
111111
} else {
112-
setTimeout(this.siguienteNivel, 1500);
112+
this.winLevel();
113113
}
114114
}
115115
} else {
116-
alert('Perdiste.');
116+
this.loseGame();
117117
}
118118
}
119+
120+
deleteClickEvents() {
121+
this.colors.forEach((item) =>
122+
item.removeEventListener('click', this.chooseColor)
123+
);
124+
}
125+
126+
winGame() {
127+
swal('Simon Colors', 'Congratulations, you win!', 'success').then(() =>
128+
this.initialize()
129+
);
130+
}
131+
132+
loseGame() {
133+
swal(
134+
'You lose :(',
135+
"But you can try it again, don't give up!",
136+
'error'
137+
).then(() => {
138+
this.deleteClickEvents();
139+
this.initialize();
140+
});
141+
}
142+
143+
winLevel() {
144+
swal('Simon Colors', 'Perfect!, next level', 'success').then(() =>
145+
setTimeout(this.siguienteNivel(), 800)
146+
);
147+
}
119148
}
120149

121150
const empezarJuego = () => {
122-
alert('El juego va a empezar.');
123-
window.juego = new Juego();
151+
swal('Simon Dice', '¡El Juego va a empezar!', 'success').then(() =>
152+
setTimeout((window.juego = new Juego()))
153+
);
124154
};

0 commit comments

Comments
 (0)