checkers.model
Class CheckersGame

java.lang.Object
  extended by java.util.Observable
      extended by checkers.model.CheckersGame
All Implemented Interfaces:
CheckersConstants

public class CheckersGame
extends java.util.Observable
implements CheckersConstants

This class is a part of the main functionality of the checkers game. Its functions include knowing whose turn it is, remembering multiple jumps, relaying end of game conditions and ending the game.

Author:

Field Summary
 
Fields inherited from interface checkers.CheckersConstants
ACCEPT, BLUE, CLIENTGAME, DRAW, HOST, HOSTGAME, JOIN, KING, LOCAL, LOCALGAME, NUM_SPACES, PLAYER1SET, PLAYER2SET, RESIGN, SINGLE, UPDATE, WHITE
 
Constructor Summary
CheckersGame(Board b)
          Constructor Create the driver, which in turn creates the rest of the system.
 
Method Summary
 void endGame(java.lang.Object msg)
          This method ends the checkers game due to whatever reason neccessary ie.
 void endInDraw(int playerNum)
          This method ends the game in a draw, alerting both players that the draw has taken place
 void endInQuit(int playerNum)
          Ends the game as a result of a player quitting, notifying each player
 void endTurn()
          This method is called after a move has been checked.
 int getCurrentTurn()
           
 java.lang.String getMessage()
           
 int getPlayerColor(int playerNumber)
          Returns color for player number passed in
 java.lang.String getPlayerName(int playerNumber)
          Returns the name of player with number passed in
 int getPlayerNum()
           
 int getSelectedIndex()
           
 boolean isGameActive()
           
 void offerDraw()
          Offer a draw
 void selectColors()
          This method sets the colors of pieces that each player will be
 boolean selectSpace(int space)
          Determines if a space is selectable based on whose turn it is.
 void setPlayer1Color(int color)
          Set the color for a player using the passed in value.
 void setPlayerName(int num, java.lang.String name)
          Set the name for the player using the passed in values.
 void setPlayerNum(int playerNum)
           
 void startGame()
          This method will start the game play.
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CheckersGame

public CheckersGame(Board b)
Constructor Create the driver, which in turn creates the rest of the system.

Method Detail

endTurn

public void endTurn()
This method is called after a move has been checked. Changes active player when a final succesful jump has been made, resets the timer when appropriate, and tells the appropriate player whos turn it is to make a move. Refactored: The method should be called when the turn is over. Checking should be completed outside of this method. It will still perform all operations needed at end of turn.

Parameters:
color - The color whose turn it will now be
space - The space on the board from which a multiple jump has to be made

endGame

public void endGame(java.lang.Object msg)
This method ends the checkers game due to whatever reason neccessary ie. a draw, someone quitting, or a victory.

Parameters:
message - the message to send to all players regarding the reason for ending the game

endInDraw

public void endInDraw(int playerNum)
This method ends the game in a draw, alerting both players that the draw has taken place


endInQuit

public void endInQuit(int playerNum)
Ends the game as a result of a player quitting, notifying each player

Parameters:
the - player who quit

selectColors

public void selectColors()
This method sets the colors of pieces that each player will be


startGame

public void startGame()
This method will start the game play. Letting the first person move their piece and so on


selectSpace

public boolean selectSpace(int space)
Determines if a space is selectable based on whose turn it is. If a space has already been selected, calls movePiece to perform a move

Parameters:
space - the space to select
Returns:
True on select or move, false otherwise

offerDraw

public void offerDraw()
Offer a draw


getPlayerName

public java.lang.String getPlayerName(int playerNumber)
Returns the name of player with number passed in

Parameters:
playerNumber - Number of player to get name for
Returns:
Player's name of number passed in

setPlayerName

public void setPlayerName(int num,
                          java.lang.String name)
Set the name for the player using the passed in values.

Parameters:
num - The player's number (1 or 2)
name - The name to assign to the player.

getPlayerColor

public int getPlayerColor(int playerNumber)
Returns color for player number passed in

Parameters:
playerNumber - Number of player to get color for
Returns:
Color for player number passed in

setPlayer1Color

public void setPlayer1Color(int color)
Set the color for a player using the passed in value.

Parameters:
num - The player's number (1 or 2)
color - The color to assign to the player.

getCurrentTurn

public int getCurrentTurn()
Returns:
Returns the color whose turn it is.

isGameActive

public boolean isGameActive()
Returns:
Returns the gameActive.

getMessage

public java.lang.String getMessage()
Returns:
Returns the message.

getSelectedIndex

public int getSelectedIndex()
Returns:
Returns the selectedIndex.

getPlayerNum

public int getPlayerNum()
Returns:
Returns the playerNum.

setPlayerNum

public void setPlayerNum(int playerNum)
Parameters:
playerNum - The playerNum to set.