Class SimpleNIM

java.lang.Object
  extended by SimpleNIM

public class SimpleNIM
extends Object

The simple NIM game. There are 21 sticks in the pile. On each move, each user take turns picking up 1, 2, or 3 sticks until there are no more sticks left. The one who picks up the last stick loses.

Author:
Namita Singla, Robert Cohen

Constructor Summary
SimpleNIM(SimpleNIMGUI simpleNIMGUI)
          The constructor.
 
Method Summary
 void displayMessage(String msg)
          Displays a message
protected  boolean gameOver(Player player)
          Game Over?
protected  Player getCurrentPlayer()
          Returns the current player
protected  int getSticksLeft()
          Returns the number of sticks left in the pile
 void pickSticks(int noOfSticks, Player turn)
          Pick up Sticks
protected  void setCurrentPlayer(Player player)
          Sets the current player
protected  void setWhoGoFirst(String whoGoFirst)
          Set which player will go first
 void start()
          Starts the game
protected  void updateSticksLeft(int picksticks)
          Updates the number of sticks left in the pile.
protected  boolean validMove(int numSticks)
          Valid move?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleNIM

public SimpleNIM(SimpleNIMGUI simpleNIMGUI)
The constructor.

Parameters:
simpleNIMGUI - The GUI associated with the game
Method Detail

start

public void start()
Starts the game


setWhoGoFirst

protected void setWhoGoFirst(String whoGoFirst)
Set which player will go first

Parameters:
whoGoFirst - The first player

updateSticksLeft

protected void updateSticksLeft(int picksticks)
Updates the number of sticks left in the pile.

Parameters:
picksticks - No. of sticks picked

gameOver

protected boolean gameOver(Player player)
Game Over?

Parameters:
player - The player
Returns:
true if the game is over.

getCurrentPlayer

protected Player getCurrentPlayer()
Returns the current player

Returns:
The current player

setCurrentPlayer

protected void setCurrentPlayer(Player player)
Sets the current player

Parameters:
player - The player

validMove

protected boolean validMove(int numSticks)
Valid move?

Parameters:
numSticks - The number of sticks picked
Returns:
true iff there are enough sticks left and numSticks is between 1 and 3

getSticksLeft

protected int getSticksLeft()
Returns the number of sticks left in the pile

Returns:
The number of sticks left in the pile

displayMessage

public void displayMessage(String msg)
Displays a message

Parameters:
msg - The message

pickSticks

public void pickSticks(int noOfSticks,
                       Player turn)
Pick up Sticks

Parameters:
noOfSticks - The number of sticks to be picked up
turn - The current player