This project is an implementation of the classic Simon Says game, created using HTML, CSS, and JavaScript. The game involves the system generating a random sequence of colors, and the player has to repeat the sequence by clicking on the corresponding colored buttons. With each correct input, the game advances to the next level, increasing the sequence length. If the player makes a mistake, the game ends, and the player's highest score is displayed.
- Random Color Sequence: The game generates a random sequence of colors, and the player must follow the sequence by pressing the corresponding colored buttons.
- Levels: Each time the player correctly follows the sequence, the level increases, and the length of the sequence grows.
- Game Over: If the player makes a mistake, the game ends, and the highest score achieved is displayed.
- Start the Game: Press any key to start the game.
- Follow the Sequence: The system will show a color pattern by flashing colored buttons. Click on the buttons in the same order.
- Progressing Levels: Each time you correctly repeat the sequence, the game moves to the next level with an added color.
- Game Over: If you click the wrong button, the game will end and show your highest score.
- The game starts when the user presses any key on the keyboard.
- A random color from a predefined set of colors (
yellow
,red
,green
,purple
) is chosen, and the sequence grows as the game progresses. - The user has to repeat the sequence by clicking the corresponding colored buttons.
- If the user presses the wrong button, the game is over, and the highest score is displayed.
- The game resets, and the player can start again by pressing any key.
- HTML: Used for creating the structure of the game, including buttons and headings.
- CSS: Used for styling the game interface, including button colors and flashing effects.
- JavaScript: Used to implement the game logic, including sequence generation, button pressing, validation, and game state management.
Key Variables:
gameSeq
: Stores the generated sequence of colors.userSeq
: Stores the user's sequence of button presses.started
: A flag to check if the game has started.level
: The current level of the game.Heighest_Score
: Tracks the highest score achieved.btns
: An array of colors representing the available buttons.
Event Listeners:
keypress
event: Starts the game when any key is pressed for the first time.click
event: Listens for button clicks and checks if the user's input matches the sequence.
Game Flow:
- Game Start: The game starts when a key is pressed, and the sequence starts at level 1.
- Sequence Generation: On each level, the game randomly selects a color and adds it to the sequence.
- Button Flashing: The button corresponding to the selected color flashes to indicate which color the player needs to click.
- User Input: The user clicks buttons in the same order as the generated sequence.
- Validation: If the user makes a mistake, the game ends and displays the highest score.
Game Over: When the player clicks a wrong button, the game displays a Game Over message along with the highest score. The background color of the page will flash red, signaling that the game is over.
Game Reset: After the game ends, the sequence and score are reset, and the player can press any key to start a new game.
- Clone the repository or download the project files.
- Open the
index.html
file in a web browser. - Play the game by pressing any key to start.
..