diff --git a/Simon Game/game.js b/Simon Game/game.js index 509f7648..0ccd8c2f 100644 --- a/Simon Game/game.js +++ b/Simon Game/game.js @@ -24,9 +24,7 @@ function nextSequence(){ var randomNumber = Math.floor(Math.random() * 3); var randomChosenColour = buttonColours[randomNumber]; gamePattern.push(randomChosenColour); - - $("#" + randomChosenColour).fadeOut(100).fadeIn(100); - playSound(randomChosenColour); + playGamePattern(0); } @@ -41,6 +39,21 @@ $(".btn").click(function(){ }); +function playGamePattern(index) { + if (index < gamePattern.length) { + $("#" + gamePattern[index]).fadeIn(100).fadeOut(100).fadeIn(100); + playSound(gamePattern[index]); + + + setTimeout(function () { + playGamePattern(index + 1); + }, 200); + } +} + +playGamePattern(0); + + function checkAnswer(currentLevel) { if (gamePattern[currentLevel] === userClickedPattern[currentLevel]) {