Advertisement
Guest User

RPS Coding

a guest
Nov 12th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. import java.util.Scanner;
  2. class Main {
  3.   public static void main(String[] args) {
  4.     boolean gameContinued = true;
  5.     boolean winnerDetermined = false;
  6.     int winner = 0; //1 is for p1  | 2 is for p2
  7.     Scanner scan = new Scanner(System.in);
  8.     String actionP1;
  9.     String actionP2;
  10.  
  11.     while(gameContinued) {
  12.           while (!winnerDetermined) {
  13.           System.out.println("Player One");
  14.           actionP1 = scan.nextLine();
  15.           System.out.println("Player Two");
  16.           actionP2 = scan.nextLine();
  17.  
  18.           if(actionP1.equals(actionP2)) {
  19.             // Do nothing
  20.           } else if (actionP1.equals("paper") && actionP2.equals("scissors")) {
  21.               winner = 2;
  22.               winnerDetermined = true;
  23.           } else if (actionP1.equals("paper") && actionP2.equals("rock")) {
  24.               winner = 1;
  25.               winnerDetermined = true;
  26.           } else if (actionP1.equals("rock") && actionP2.equals("paper")) {
  27.               winner = 2;
  28.               winnerDetermined = true;
  29.           } else if (actionP1.equals("rock") && actionP2.equals("scissors")) {
  30.               winner = 1;
  31.               winnerDetermined = true;
  32.           } else if (actionP1.equals("scissors") && actionP2.equals("rock")) {
  33.               winner = 2;
  34.               winnerDetermined = true;
  35.           } else if (actionP1.equals("scissors") && actionP2.equals("paper")) {
  36.               winner = 1;
  37.               winnerDetermined = true;
  38.           }
  39.         }
  40.        
  41.         if(winner == 1) {
  42.           System.out.println("Player One Winner");
  43.         } else {
  44.           System.out.println("Player Two Winner");
  45.         }
  46.     }
  47.         System.out.println("Continue?");
  48.       if(scan.nextLine().equals("no")) {
  49.         gameContinued = false;
  50.       }
  51.     }
  52.   }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement