filipparodriguezz

Untitled

Dec 12th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.  
  4.     public static void main(String[] args) {
  5.  
  6.  
  7.         Scanner keyboard = new Scanner(System.in);
  8.  
  9.         int pileA = 3;
  10.         int pileB = 3;
  11.         int pileC = 3;
  12.  
  13.         String player1;
  14.         String player2;
  15.         String currentPlayer = "";
  16.  
  17.         String pile = " ";
  18.         int remove;
  19.  
  20.         System.out.println("Player 1, enter your name: ");
  21.         player1 = keyboard.next();
  22.  
  23.         System.out.println("Player 2, enter your name: ");
  24.         player2 = keyboard.next();
  25.  
  26.         if (pileA > 0 || pileB > 0 || pileC > 0)
  27.             do {
  28.                 System.out.print(" A:" + pileA);
  29.  
  30.                 System.out.print(" B:" + pileB);
  31.  
  32.                 System.out.print(" C:" + pileC);
  33.  
  34.                 System.out.println("\n" + player1 + ", Choose a pile: ");
  35.                 pile = keyboard.next();
  36.  
  37.                 System.out.println("How many to remove from pile " + pile + ": ");
  38.                 remove = keyboard.nextInt();
  39.  
  40.                 if (pile.equals("A")) {
  41.                     pileA = pileA - remove;
  42.  
  43.  
  44.                 } else if (pile.equals("B")) {
  45.                     pileB = pileB - remove;
  46.  
  47.  
  48.                 } else if (pile.equals("C")) {
  49.                     pileC = pileC - remove;
  50.  
  51.                 }
  52.                 if (pileA > 0 || pileB > 0 || pileC > 0)
  53.                     do {
  54.                         System.out.print("A:" + pileA);
  55.  
  56.                         System.out.print(" B:" + pileB);
  57.  
  58.                         System.out.print(" C:" + pileC);
  59.  
  60.                         System.out.println("\n" + player2 + ", Choose a pile: ");
  61.                         pile = keyboard.next();
  62.  
  63.                         System.out.println("How many to remove from pile " + pile + ": ");
  64.                         remove = keyboard.nextInt();
  65.  
  66.                         if (pile.equals("A")) {
  67.                             pileA = pileA - remove;
  68.  
  69.  
  70.                         } else if (pile.equals("B")) {
  71.                             pileB = pileB - remove;
  72.  
  73.  
  74.                         } else if (pile.equals("C")) {
  75.                             pileC = pileC - remove;
  76.  
  77.                             if (pileA + pileB + pileC == 0 && currentPlayer.equals(player1)) {
  78.                                 System.out.println("A: " + pileA + " B: " + pileB + " C: " + pileC);
  79.                                 System.out.println("All piles are empty, Good job! YOU WON, " + player1 + "!");
  80.  
  81.                             } else {
  82.                                 System.out.println("A: " + pileA + " B: " + pileB + " C: " + pileC);
  83.                                 System.out.println("All piles are empty, Good job! YOU WON,  " + player2 + " !");
  84.                             }
  85.                         }
  86.                     } while (pileA > 0 || pileB > 0 || pileC > 0);
  87.             } while (pileA > 0 || pileB > 0 || pileC > 0);
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment