import java.util.*;

/**
 * This class functions as both the "entry point" for the game, as
 * well as the "controller" for the game, i.e., it manages the game logic.
 * If the game logic is sufficiently complex, or if we need to support multiple
 * distinct Game objects, it would make sense to move this code into its own
 * class.
 */
public class Game {
   public static void main(String[] args) {
      Scanner in = new Scanner(System.in);

      String name;

System.out.print("Player 1's name? "); name = in.next(); Player p1 = new Player(name); System.out.print("Player 2's name? "); name = in.next(); Player p2 = new Player(name);
System.out.print("How many sticks? "); int numSticks = in.nextInt(); Pile pile = new Pile(numSticks);
boolean done = false; // This is our flag to check if the game is over or not.
while (!done) { System.out.print(p1.getName() + ", how many sticks do you want to take? "); int sticksToRemove = in.nextInt(); p1.takeTurn(pile, sticksToRemove); System.out.println(p1 + " takes " + sticksToRemove + " stick(s).\n" + "There are " + pile.getSticks() + " left in the pile."); if (pile.getSticks() <= 0) { done = true; System.out.println(p2 + " is the winner"); } else { System.out.print(p2.getName() + ", how many sticks do you want to take? "); sticksToRemove = in.nextInt(); p2.takeTurn(pile, sticksToRemove); System.out.println(p2 + " takes " + sticksToRemove + " stick(s).\n" + "There are " + pile.getSticks() + " left in the pile."); if (pile.getSticks() <= 0) { done = true; System.out.println(p1 + " is the winner"); } } }
in.close(); } }