From 1a4641489849bcf09eab87f17c58c08b0d416497 Mon Sep 17 00:00:00 2001 From: Rutuj Kamewar <143892404+Rutuj-kamewar@users.noreply.github.com> Date: Fri, 27 Oct 2023 00:52:17 +0530 Subject: [PATCH] Update game.js Added a timeout for bot moves and animation bot will also play the sequence --- Simon Game/game.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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]) {