Skip to content

MeetInCode/Simon_Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simon Game

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.

Files Included

  • 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.

How to Play

  1. Press any key to start the game.
  2. Follow the sequence of button presses (colors) generated by the game.
  3. Click the buttons in the same sequence as displayed.
  4. If you successfully repeat the sequence, the game will generate a new sequence with an additional button press.
  5. The game continues until you make a mistake.
  6. When you make a mistake, the game will display "Game Over, Press Any Key to Restart" and will reset.

JavaScript Code Overview

Variables

  • 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.

Event Listeners

  • $(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.

Functions

  • 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.

How the Game Works

  1. The game starts by pressing any key, initializing the level to 0 and calling nextSequence().
  2. nextSequence() generates a random color, adds it to the gamePattern, and displays it to the user.
  3. When the user clicks a button, their choice is recorded in userClickedPattern, and the game checks if the choice is correct using checkAnswer().
  4. If the user's input is correct and complete, nextSequence() is called again to add another color to the sequence.
  5. If the user makes a mistake, the game plays a "wrong" sound, displays "Game Over", and resets using startOver().

Dependencies

  • jQuery: Used for DOM manipulation and event handling.

Running the Game

  1. Clone the repository or download the files.
  2. Open index.html in a web browser.
  3. Press any key to start the game and follow the instructions.

Enjoy playing the Simon Game!

About

The Simon_Game is a web-based implementation of the classic electronic memory game "Simon."

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published