/Simon-Game

Simon Game developed with hints and stack overflow from Dr. Angela Yu's Bootcamp. Purpose of the project to develop a better understanding of how to write code using jquery. Additionally, the project focuses on producing and interpreting a sequence of inputs while providing the user visual and audio feedback.

Primary LanguageJavaScript

Simon Says jQuery

The "Simon Says" jQuery script is a simple implementation of the classic memory game "Simon Says." Players are required to repeat a sequence of colored buttons in the correct order as presented by the game. This documentation provides an overview of the script's functionality and the purpose of each function and variable within the code.

Table of Contents

  1. Introduction
  2. Global Variables
  3. Initialization
  4. Game Logic
  5. User Interaction
  6. Helper Functions
  7. Conclusion

1. Introduction

The "Simon Says" game is implemented using jQuery, a popular JavaScript library, to create an interactive and engaging user experience. Players are challenged to remember and repeat sequences of colors in the correct order. The game comprises a series of levels, each increasing in complexity.

2. Global Variables

  • buttonColors: An array containing the possible colors of buttons.
  • gamePattern: An array storing the randomly generated sequence of colors presented by the game.
  • userClickedPattern: An array tracking the sequence of colors clicked by the user.
  • started: A boolean variable indicating whether the game has started.
  • level: An integer representing the current level of the game.

3. Initialization

The game starts when a key is pressed. When a key is detected, the game initializes with the nextSequence function, which generates the first color sequence and increments the level.

4. Game Logic

  • nextSequence(): This function generates the next color in the sequence, displays the color's button with fading animation, and plays a sound associated with the color.

5. User Interaction

  • $(document).keypress(function()): Detects a key press to start the game if it hasn't already begun.
  • $(".btn").click(function()): Detects button clicks, adds the clicked color to userClickedPattern, plays the corresponding sound, and animates the button press effect. It also calls checkAnswer to verify if the user's sequence matches the game's sequence.

6. Helper Functions

  • playSound(name): Plays an audio file associated with a given color's name.
  • animatePress(currentColor): Animates the button press effect for a specified color by adding and removing a CSS class.
  • checkAnswer(currentLevel): Compares the user's clicked sequence with the game's sequence up to the current level. If the sequences match, the game proceeds to the next level. If not, the game ends, and the user is prompted to restart.

7. Conclusion

The "Simon Says" jQuery script provides a functional implementation of the classic memory game. It utilizes various functions and global variables to manage game logic, user interaction, and audio-visual effects. By understanding and customizing this script, developers can create their own interactive memory games and learn from its use of jQuery for enhanced user experiences.