checkers.model
Class Board

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

public class Board
extends java.util.Observable
implements CheckersConstants

This class represents the board on which checkers is being played. The board holds a collection of pieces.

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
Board()
          This constructor creates a new board at the beginning of the game
 
Method Summary
 int colorAt(int space)
          This method returns the color of the piece at a certain space
 Piece getPieceAt(int space)
          This method returns the piece at the certain position
 java.util.Vector getPieces(int color)
          This method is a replacement for bluePieces and whitePieces.
 boolean hasPieceOf(int color)
          This method returns if there is a piece of color on the board
 void kingPiece(int space)
          This method creates a king piece
 boolean movePiece(Move theMove)
          Move the piece at the start position to the end position
 boolean occupied(int space)
          This method checks if the space on the board contains a piece
 void removePiece(int space)
          This method removes piece at the position space
 int sizeOf()
          This method returns the size of the board
 
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

Board

public Board()
This constructor creates a new board at the beginning of the game

Method Detail

movePiece

public boolean movePiece(Move theMove)
Move the piece at the start position to the end position

Parameters:
theMove - - current location of the piece
Returns:
whether the piece was successfully moved

occupied

public boolean occupied(int space)
This method checks if the space on the board contains a piece

Parameters:
space - - the space that needs to be checked
Returns:
true or false depending on the situation

removePiece

public void removePiece(int space)
This method removes piece at the position space

Parameters:
space - - the positon of the piece to be removed

kingPiece

public void kingPiece(int space)
This method creates a king piece

Parameters:
space - - the position at which the king piece is created

colorAt

public int colorAt(int space)
This method returns the color of the piece at a certain space

Parameters:
space - - the position of the piece on the board
Returns:
the color of this piece, -1 if empty

getPieceAt

public Piece getPieceAt(int space)
This method returns the piece at the certain position

Parameters:
space - - the space of the piece
Returns:
the piece at that space, null if space is empty

hasPieceOf

public boolean hasPieceOf(int color)
This method returns if there is a piece of color on the board

Parameters:
color - - the color of the piece (as defined by constants in Piece)
Returns:
true if there is a piece of color left on the board else return false

sizeOf

public int sizeOf()
This method returns the size of the board

Returns:
the size of the board, always same as size of piece array

getPieces

public java.util.Vector getPieces(int color)
This method is a replacement for bluePieces and whitePieces. It is more general and will return a vector of all pieces of the color passed as a parameter

Parameters:
color - Color of pieces to get (as defined by constants in class Piece)
Returns:
a vector of Pieces of the given color