|
|||||
| PREV CLASS NEXT CLASS | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||
java.lang.Object | +--sandy.game.core.GameBoard
This class represents an abstract GameBoard for any multi-player, tabular, strategy games likes Chess, Tic-Tac-Toe, Draught, Othello, Chinese-Checkers etc. This class provides the following functionality to its sub-classes:
positions
for keeping track of the positions on the board. Position is again
a generic concept which specific games should implement.
| Field Summary | |
protected java.util.Stack |
moves
|
protected int |
numCols
|
protected int |
numRows
|
protected Position[][] |
positions
|
| Constructor Summary | |
protected |
GameBoard(int numRows,
int numCols)
The constructor which takes the number of rows and columns in the game board. |
| Method Summary | |
void |
addMoveListener(GameBoardMoveListener moveListener)
|
abstract java.util.Vector |
getAllPossibleMoves(int perspective)
This abstract method should be implemented by the sub-classes to provide logic to return all the possible moves for a given perspective at the current state of the board. |
abstract int |
getEnemyPerspective(int currentPerspective)
This function should return the opponent perspective for the given currentPerspective. |
int |
getNumCols()
|
int |
getNumRows()
|
Position |
getPosition(int row,
int col)
Gets a specific position in the game board as specified by the row and col parameters. |
abstract GameBoard |
getScratchBoard()
This function should be implemented by the subclasses to return a DEEP COPY of the gameboard in the current state. |
abstract void |
initializeBoard()
This is an abstract call back method, which is invoked during the board construction time (constructor). |
abstract boolean |
isGameActive()
This function should return whether the game is active. |
abstract boolean |
isValidMove(Move move)
This function should analyze the given move and return whether the move is a valid move or not. |
void |
makeMove(Move move)
Make a move on the game board. |
abstract void |
printBoard()
This is a debug function, which is used to print the board. |
void |
removeMoveListener(GameBoardMoveListener moveListener)
|
abstract void |
undoLastMove()
This function should undo the last move made. |
abstract void |
updateGameBoard(Move move)
This abstract method is called when a move is made on the board. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected int numRows
protected int numCols
protected Position[][] positions
protected java.util.Stack moves
| Constructor Detail |
protected GameBoard(int numRows,
int numCols)
initializeBoard, which
should be implemented by the sub-classes to provide logic for initializing the
gameboard to an initial or a predefined state.| Method Detail |
public abstract void initializeBoard()
public abstract java.util.Vector getAllPossibleMoves(int perspective)
perspective - The perspective in the board. Perspective can be thought of as a side
in the game. This is a game dependent concept, for example in Tic-Tac-Toe
perspective can mean either CROSS or CIRCLE, in Chess it may mean either
BLACK or WHITE.. etc.public void makeMove(Move move)
updateGameBoard, which should be implemented the specific logic of making
a move, also this method informs all the move listeners of the following events.
move - The game specific move.public abstract void updateGameBoard(Move move)
public abstract void undoLastMove()
moves.public abstract boolean isValidMove(Move move)
public abstract int getEnemyPerspective(int currentPerspective)
public abstract boolean isGameActive()
public abstract GameBoard getScratchBoard()
public abstract void printBoard()
public void addMoveListener(GameBoardMoveListener moveListener)
public void removeMoveListener(GameBoardMoveListener moveListener)
public int getNumRows()
public int getNumCols()
public Position getPosition(int row,
int col)
| PREV CLASS NEXT CLASS | ||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |