Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- String player1;
- String player2;
- int pileA = 3;
- int pileB = 3;
- int pileC = 3;
- String choice;
- int remove;
- System.out.println("\n Welcome!");
- System.out.println("\n Player 1, enter your name: ");
- player1 = keyboard.next();
- System.out.println("\n Player 2, enter your name: ");
- player2 = keyboard.next();
- System.out.println("\n A:"+pileA+" B:"+pileB+" C:"+pileC);
- String player = player1;
- do{
- System.out.println("\n" + player + ", choose a pile:");
- choice = keyboard.next();
- while ((choice.equals("A") && pileA <= 0) || (choice.equals("B") && pileB <= 0) || (choice.equals("C") && pileC <= 0)){
- System.out.println("\n Nice try "+player+". That pile is empty. Choose again:");
- choice = keyboard.next();
- }
- System.out.println("\n How many to take out from pile "+choice);
- remove = keyboard.nextInt();
- while((choice.equals("A") && remove > pileA) || (choice.equals("B") && remove > pileB) || (choice.equals("C") && remove > pileC)){
- System.out.println("\n Good try "+player+". Your amount is not valid. Try again:");
- remove = keyboard.nextInt();
- }
- while (remove < 0){
- System.out.println("\n Good try "+player+". Your amount is not valid. Try again:");
- remove = keyboard.nextInt();
- }
- if(choice.equals("A")){
- System.out.println("\n A:"+(pileA - remove)+" B:"+pileB+" C:"+pileC);
- pileA = pileA - remove;
- }
- else if(choice.equals("B")){
- System.out.println("\n A:"+pileA+" B:"+(pileB - remove)+" C:"+pileC);
- pileB = pileB - remove;
- }
- else if(choice.equals("C")){
- System.out.println("\n A:"+pileA+" B:"+pileB+" C:"+(pileC - remove));
- pileC = pileC - remove;
- }
- else{
- System.out.println("\n ERROR! Choose a correct pile (case sensitive)");
- }
- if(player == player1){
- player = player2;
- }
- else {
- player = player1;
- }
- }while (pileA > 0 || pileB > 0 || pileC > 0);
- System.out.println("\n "+player + ", there are no counters left, so you WIN!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement