Skip to content

Otormin/RockPaperScissors

Repository files navigation


🪨📄✂️ Rock Paper Scissors

A dynamic, browser-based implementation of the classic hand game. This project allows users to play against a computer, featuring customizable game lengths and persistent player personalization using Local Storage.

📖 Overview

This is a JavaScript-driven application where players compete against a randomized computer opponent. Unlike a simple "best of 1" game, this version allows users to define the number of rounds they wish to play before the game starts, tracking the score in real-time until the limit is reached.

📸 Screenshots

Homepage Gameplay page Finished game page

✨ Key Features

  • Customizable Game Length: The game retrieves the number of rounds (PlayerRounds) from Local Storage, allowing for short or marathon sessions.
  • Personalization: Displays the player's name dynamically, retrieved from the setup screen.
  • Visual Feedback: The computer's choice is visually represented by changing images (rock.jpeg, paper.jpg, etc.) dynamically in the DOM.
  • Score Tracking: Real-time updates of Player vs. Computer scores after every round.
  • Session Management: Options to "Play Again" (reload) or "Quit" (return to the start screen) appear automatically when the match ends.

🕹️ How to Play

  1. Setup: (On the index page) Enter your Name and the number of Rounds you want to play.
  2. Make your Move: Click on Rock, Paper, or Scissors.
  3. The Result:
  • The computer randomly selects its move.
  • The score updates based on standard rules:
  • 🪨 beats ✂️
  • ✂️ beats 📄
  • 📄 beats 🪨
  1. Game Over: Once the round limit is reached, the game announces the winner via an alert and offers a rematch.

🛠️ Tech Stack

  • Frontend: HTML5, CSS3
  • Logic: Vanilla JavaScript (ES6)
  • Storage: Browser LocalStorage API (for Name and Round settings)

📂 Code Logic

The core logic relies on random number generation and event listeners for the three buttons. Here is how the computer makes a choice:

function computerPlay(){
    let display = "";
    let randomNumber = 0;

    // Generates 0, 1, or 2 representing Rock, Paper, or Scissors
    for( let i = 0; i <= 1; i++){
        randomNumber = Math.floor(Math.random()*3);
        display = `<img src = ${imageStorage[randomNumber]}>`;
    }

    // Updates the UI with the computer's image
    imageDisplayComputer.innerHTML = display;
    return randomNumber;
}

🚀 Installation & Run

  1. Clone the repository:
git clone https://github.com/Otormin/RockPaperScissors.git
  1. Navigate to the folder:
cd RockPaperScissors
  1. Launch: Open the index.html file in your browser to set up your player details, which will then redirect you to the main game board.

About

A dynamic Rock-Paper-Scissors game against a computer opponent, featuring customizable round limits and score tracking via LocalStorage.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors