https://github.com/lunarwhite/rock-paper-scissors
Classic game: Rock, Paper, Scissors.
https://github.com/lunarwhite/rock-paper-scissors
console-game game java rock-paper-scissors rps
Last synced: 4 months ago
JSON representation
Classic game: Rock, Paper, Scissors.
- Host: GitHub
- URL: https://github.com/lunarwhite/rock-paper-scissors
- Owner: lunarwhite
- License: mit
- Created: 2021-08-28T08:57:46.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-14T17:55:55.000Z (over 1 year ago)
- Last Synced: 2024-12-26T08:41:57.355Z (6 months ago)
- Topics: console-game, game, java, rock-paper-scissors, rps
- Language: Java
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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()`
```java
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
```java
Scanner keyboard = new Scanner(System.in);
Keyboard.nextLine(); // clear line
```