Class GameBoard

java.lang.Object
  extended by GameBoard
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
OthelloBoard

public abstract class GameBoard
extends java.lang.Object
implements java.io.Serializable

This class manages the data necessary for a Game board. The class is abstract so different types of game boards can be implemented (ie. chess, othello, checkers)

Author:
Adam Hauer Stony Brook University
See Also:
Serialized Form

Field Summary
static int NOTHING
          Used to specify cells that are not occupied by any player
static int P1
          Used to specify cells occupied by player 1
static int P2
          Used to specify cells occupied by player 2
 
Constructor Summary
GameBoard(int initRow, int initCol)
          Constructor for starting a game with an empty board of size [initRow][initCol].
 
Method Summary
abstract  void chooseCell(int row, int col, int player)
          Method to allow a player to select a cell.
 int getCell(int irow, int jcol)
          Accessor method to return the value in a certain cell
 int getTurn()
          Accessor method that provides the current players turn
abstract  int getWinner()
          Determines who has won the game.
abstract  boolean isLegalMove(java.awt.Dimension testMove)
          This method checks if the selected move is allowed by the current player
abstract  void resetBoard()
          Method to reset the entire board, assigning all cells to have value of NOTHING.
 void skipTurn()
          Method for skipping the current player's turn
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOTHING

public static int NOTHING
Used to specify cells that are not occupied by any player


P1

public static int P1
Used to specify cells occupied by player 1


P2

public static int P2
Used to specify cells occupied by player 2

Constructor Detail

GameBoard

public GameBoard(int initRow,
                 int initCol)
Constructor for starting a game with an empty board of size [initRow][initCol].

Parameters:
initRow - - number of rows on the board
initCol - - number of columns on the board
Method Detail

getCell

public int getCell(int irow,
                   int jcol)
Accessor method to return the value in a certain cell

Parameters:
dim - - row/col of the chosen cell
Returns:
- the player (P1 or P2) that occupies that cell or NOTHING if no player occupies the cell

getTurn

public int getTurn()
Accessor method that provides the current players turn

Returns:
- (P1 or P2) depending on whose turn it is

skipTurn

public void skipTurn()
Method for skipping the current player's turn


resetBoard

public abstract void resetBoard()
Method to reset the entire board, assigning all cells to have value of NOTHING.


chooseCell

public abstract void chooseCell(int row,
                                int col,
                                int player)
Method to allow a player to select a cell. Makes the necessary changes to the game board as well. Also changes the turn so the next player can move

Parameters:
dim - - row/col of the chosen cell

isLegalMove

public abstract boolean isLegalMove(java.awt.Dimension testMove)
This method checks if the selected move is allowed by the current player

Parameters:
testMove - - the row/column of the move being queried
Returns:
- TRUE if legal and FALSE if not.

getWinner

public abstract int getWinner()
Determines who has won the game.

Returns:
- P1 if player 1 has won, P2 if player 2 has won, NOTHING if a tie