File tree 1 file changed +15
-18
lines changed
1 file changed +15
-18
lines changed Original file line number Diff line number Diff line change 1
-
2
1
var buttonColours = [ "red" , "blue" , "green" , "yellow" ] ;
3
2
4
3
var gamePattern = [ ] ;
@@ -28,23 +27,23 @@ $(".btn").click(function() {
28
27
29
28
function checkAnswer ( currentLevel ) {
30
29
31
- if ( gamePattern [ currentLevel ] === userClickedPattern [ currentLevel ] ) {
32
- if ( userClickedPattern . length === gamePattern . length ) {
33
- setTimeout ( function ( ) {
34
- nextSequence ( ) ;
35
- } , 1000 ) ;
36
- }
37
- } else {
38
- playSound ( "wrong" ) ;
39
- $ ( "body" ) . addClass ( "game-over" ) ;
40
- $ ( "#level-title" ) . text ( "Game Over, Press Any Key to Restart" ) ;
41
-
30
+ if ( userClickedPattern . length > 0 && gamePattern [ currentLevel ] === userClickedPattern [ currentLevel ] ) {
31
+ if ( userClickedPattern . length === gamePattern . length ) {
42
32
setTimeout ( function ( ) {
43
- $ ( "body" ) . removeClass ( "game-over" ) ;
44
- } , 200 ) ;
45
-
46
- startOver ( ) ;
33
+ nextSequence ( ) ;
34
+ } , 1000 ) ;
47
35
}
36
+ } else {
37
+ playSound ( "wrong" ) ;
38
+ $ ( "body" ) . addClass ( "game-over" ) ;
39
+ $ ( "#level-title" ) . text ( "Game Over, Press Any Key to Restart" ) ;
40
+
41
+ setTimeout ( function ( ) {
42
+ $ ( "body" ) . removeClass ( "game-over" ) ;
43
+ } , 200 ) ;
44
+
45
+ startOver ( ) ;
46
+ }
48
47
}
49
48
50
49
@@ -77,5 +76,3 @@ function startOver() {
77
76
gamePattern = [ ] ;
78
77
started = false ;
79
78
}
80
-
81
-
You can’t perform that action at this time.
0 commit comments