diff --git a/.gitignore b/.gitignore index c851038..8633718 100644 --- a/.gitignore +++ b/.gitignore @@ -99,5 +99,4 @@ hs_err_pid* .idea/discord.xml .idea/google-java-format.xml .idea/misc.xml -readme.md -src/ +src/META-INF diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..04737a4 --- /dev/null +++ b/readme.md @@ -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. diff --git a/src/me/boa/rps/RPS.java b/src/me/boa/rps/RPS.java new file mode 100644 index 0000000..280815b --- /dev/null +++ b/src/me/boa/rps/RPS.java @@ -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 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 + "."); + } + } +}