Advertisement
Guest User

Untitled

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