Skip to content

Commit

Permalink
abc
Browse files Browse the repository at this point in the history
  • Loading branch information
boafur committed Sep 30, 2020
1 parent 6071726 commit 4b88701
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ hs_err_pid*
.idea/discord.xml
.idea/google-java-format.xml
.idea/misc.xml
readme.md
src/
src/META-INF
5 changes: 5 additions & 0 deletions readme.md
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.
41 changes: 41 additions & 0 deletions src/me/boa/rps/RPS.java
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 + ".");
}
}
}

0 comments on commit 4b88701

Please sign in to comment.