Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- boolean gameContinued = true;
- boolean winnerDetermined = false;
- int winner = 0; //1 is for p1 | 2 is for p2
- Scanner scan = new Scanner(System.in);
- String actionP1;
- String actionP2;
- while(gameContinued) {
- while (!winnerDetermined) {
- System.out.println("Player One");
- actionP1 = scan.nextLine();
- System.out.println("Player Two");
- actionP2 = scan.nextLine();
- if(actionP1.equals(actionP2)) {
- // Do nothing
- } else if (actionP1.equals("paper") && actionP2.equals("scissors")) {
- winner = 2;
- winnerDetermined = true;
- } else if (actionP1.equals("paper") && actionP2.equals("rock")) {
- winner = 1;
- winnerDetermined = true;
- } else if (actionP1.equals("rock") && actionP2.equals("paper")) {
- winner = 2;
- winnerDetermined = true;
- } else if (actionP1.equals("rock") && actionP2.equals("scissors")) {
- winner = 1;
- winnerDetermined = true;
- } else if (actionP1.equals("scissors") && actionP2.equals("rock")) {
- winner = 2;
- winnerDetermined = true;
- } else if (actionP1.equals("scissors") && actionP2.equals("paper")) {
- winner = 1;
- winnerDetermined = true;
- }
- }
- if(winner == 1) {
- System.out.println("Player One Winner");
- } else {
- System.out.println("Player Two Winner");
- }
- }
- System.out.println("Continue?");
- if(scan.nextLine().equals("no")) {
- gameContinued = false;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement