File tree 1 file changed +35
-5
lines changed
1 file changed +35
-5
lines changed Original file line number Diff line number Diff line change @@ -107,18 +107,48 @@ class Juego {
107
107
this . nivel ++ ;
108
108
this . eliminarEventosClick ( ) ;
109
109
if ( this . nivel === ULTIMO_NIVEL + 1 ) {
110
- // Ganó!
110
+ this . winGame ( ) ;
111
111
} else {
112
- setTimeout ( this . siguienteNivel , 1500 ) ;
112
+ this . winLevel ( ) ;
113
113
}
114
114
}
115
115
} else {
116
- alert ( 'Perdiste.' ) ;
116
+ this . loseGame ( ) ;
117
117
}
118
118
}
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
+ }
119
148
}
120
149
121
150
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
+ ) ;
124
154
} ;
You can’t perform that action at this time.
0 commit comments