-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,5 +99,4 @@ hs_err_pid* | |
.idea/discord.xml | ||
.idea/google-java-format.xml | ||
.idea/misc.xml | ||
readme.md | ||
src/ | ||
src/META-INF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Rock, paper, scissors built in java | ||
|
||
Basic rps | ||
|
||
I've included a pre-compiled jar in the [releases](https://github.com/boafur/RPS/releases/latest "latest release"), all you need to do is download it and run it in a CLI using Java 1.8 or higher. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package me.boa.rps; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Random; | ||
import java.util.Scanner; | ||
|
||
public class RPS { | ||
public static void main(String[] args) { | ||
Random rand = new Random(); | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
ArrayList<String> choices = new ArrayList<>(); | ||
|
||
choices.add("rock"); | ||
choices.add("paper"); | ||
choices.add("scissors"); | ||
|
||
Object rock = choices.get(0); | ||
Object paper = choices.get(1); | ||
Object scissors = choices.get(2); | ||
|
||
int cpuChoiceInt = rand.nextInt(2); | ||
System.out.println("Rock, paper, or scissors?"); | ||
String choice = scanner.nextLine().toLowerCase(); | ||
Object choiceCPU = choices.get(cpuChoiceInt).toLowerCase(); | ||
|
||
if (!choice.equals(choices.get(0)) && !choice.equals(choices.get(1)) && !choice.equals(choices.get(2))) { | ||
System.out.println("That's not a valid option! Please choose rock, paper, or scissors."); | ||
} else if (choice.equals(choiceCPU)) { | ||
System.out.println("We tied, you picked " + choice.toLowerCase() + " and I picked " + choiceCPU + "."); | ||
} else if (choice.toLowerCase().equals(rock) && choiceCPU.equals(paper)) { | ||
System.out.println("I win! You chose rock and I chose paper."); | ||
} else if (choice.toLowerCase().equals(scissors) && choiceCPU.equals(rock)) { | ||
System.out.println("I win! You chose scissors and I chose rock."); | ||
} else if (choice.toLowerCase().equals(paper) && choiceCPU.equals(scissors)) { | ||
System.out.println("I win! You chose paper and I chose scissors."); | ||
} else { | ||
System.out.println("You win! I chose " + choiceCPU + " and you chose " + choice + "."); | ||
} | ||
} | ||
} |