Skip to content

Commit cd4aefa

Browse files
authoredOct 29, 2024··
Merge pull request #701 from SreejaVeerappan/patch-28
Update game.js
2 parents e1c7e42 + d90a0fa commit cd4aefa

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed
 

‎Simon_Game/game.js

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
var buttonColours = ["red", "blue", "green", "yellow"];
32

43
var gamePattern = [];
@@ -28,23 +27,23 @@ $(".btn").click(function() {
2827

2928
function checkAnswer(currentLevel) {
3029

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){
4232
setTimeout(function () {
43-
$("body").removeClass("game-over");
44-
}, 200);
45-
46-
startOver();
33+
nextSequence();
34+
}, 1000);
4735
}
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+
}
4847
}
4948

5049

@@ -77,5 +76,3 @@ function startOver() {
7776
gamePattern = [];
7877
started = false;
7978
}
80-
81-

0 commit comments

Comments
 (0)
Please sign in to comment.