This project is a simple implementation of the classic "Simon Game" using JavaScript, jQuery, HTML, and CSS. The objective of the game is to remember and reproduce the sequence of button presses generated by the game.
index.html: The main HTML file that contains the structure of the game.styles.css: The CSS file that styles the game.game.js: The JavaScript file that contains the game logic.
- Press any key to start the game.
- Follow the sequence of button presses (colors) generated by the game.
- Click the buttons in the same sequence as displayed.
- If you successfully repeat the sequence, the game will generate a new sequence with an additional button press.
- The game continues until you make a mistake.
- When you make a mistake, the game will display "Game Over, Press Any Key to Restart" and will reset.
buttonColours: An array containing the possible colors for the game buttons.gamePattern: An array that stores the sequence generated by the game.userClickedPattern: An array that stores the sequence entered by the user.started: A boolean flag to check if the game has started.level: A counter to keep track of the game level.
$(document).keypress(function() {...}): Starts the game when any key is pressed.$(".btn").click(function(event) {...}): Handles button clicks, plays sounds, animates button presses, and checks the user's input against the game sequence.
checkAnswer(currentLevel): Checks if the user's current input matches the game sequence. If the sequence matches, it proceeds to the next level. If not, it ends the game.nextSequence(): Generates the next sequence in the game, updates the level, and displays the sequence to the user.animatePress(currentColor): Animates the button press by adding and removing a CSS class.playSound(name): Plays a sound corresponding to the button pressed.startOver(): Resets the game variables to start a new game.
- The game starts by pressing any key, initializing the level to 0 and calling
nextSequence(). nextSequence()generates a random color, adds it to thegamePattern, and displays it to the user.- When the user clicks a button, their choice is recorded in
userClickedPattern, and the game checks if the choice is correct usingcheckAnswer(). - If the user's input is correct and complete,
nextSequence()is called again to add another color to the sequence. - If the user makes a mistake, the game plays a "wrong" sound, displays "Game Over", and resets using
startOver().
- jQuery: Used for DOM manipulation and event handling.
- Clone the repository or download the files.
- Open
index.htmlin a web browser. - Press any key to start the game and follow the instructions.
Enjoy playing the Simon Game!