Skip to content

lunarwhite/rock-paper-scissors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

rock-paper-scissors

Simple Java console program: Rock, Paper Scissors (RPS) Game.

Overview

  • A computerized version of Rock, Paper Scissors (RPS).
  • RPS is a popular game played between 2 individuals for decision making ("if you win, then I get the last cookie") or just for fun.
  • This time is played between the computer and a single player.

Rules

  • Rock beats Scissors (i.e., Rock wins)
  • Scissors beats Paper
  • Paper beats Rock
  • If the players pick the same thing (e.g., Rock and Rock), then it is a Tie.

Guide

  • Ask for the player's name. Say "Hello, ".
  • Ask the player "How many times do you want to play?". Repeat the game that many times.
  • The player is asked for a throw and enters "Rock", "Paper", or "Scissors". Upper case and lower case letter do not matter.
  • The computer tells the player what their number corresponded to: rock, paper, or scissors.
  • The computer picks a random number for rock, paper, or scissors.
  • If the player enters a wrong word, like "Potato", the program will say "You did not say Rock, Paper, or Scissors! No fair!". Then, it will ask them to pick again.
  • The computer tells the player what the computer picked: rock, paper, or scissors.
  • The computer tells the player who won: the player or the computer or a Tie.
  • Print the game summary to the console.

To improve

  • decideWinner()
    if (computerThrow == (playerThrow + 1) % 3) {
      System.out.println("Computer wins!");
    }
  • Only need one Scanner.
  • getPlayerThrow(), the while loop is complicated. Use Enum.
  • Clean the scanner input
    Scanner keyboard = new Scanner(System.in);
    
    Keyboard.nextLine(); // clear line

Releases

No releases published

Packages

No packages published

Languages