|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Observable | +--tictactoe.AbstractBoardGame
AbstractBoardGame implements common methods to TicTacToe and Gomoku.
BoardGame
,
TicTacToe
,
Gomoku
Field Summary | |
protected int |
_cols
|
protected Player[][] |
_gameState
|
protected Player |
_nobody
|
protected Player[] |
_player
|
protected int |
_rows
|
protected int |
_squaresLeft
|
protected int |
_turn
|
protected Player |
_winner
|
protected int |
_winningScore
|
Constructor Summary | |
AbstractBoardGame()
|
Method Summary | |
void |
addObserver(RemoteObserver remote)
Wraps a RemoteObserver to behave like a regular Observer (which does not throw any RemoteException) so we can directly use the inherited Observable methods. |
protected void |
assert(boolean assertion)
|
protected void |
checkWinner(int col,
int row)
This algorithm works both for TicTacToe and Gomoku. |
int |
cols()
|
Player |
currentPlayer()
|
Player |
get(int col,
int row)
Used by Runner to detect a winning run of marks. |
protected void |
init(int cols,
int rows,
int score,
Player playerX,
Player playerO)
Generic initialization for BoardGame. |
protected void |
initFailed(AssertionException err)
|
boolean |
inRange(int col,
int row)
|
void |
move(int col,
int row,
Player p)
Called by the current player. |
boolean |
notOver()
The game is not over as long as there is no winner and somebody can still make a move ... |
Player |
player(int n)
Return Player #n (0 or 1), else Player "nobody". |
int |
rows()
|
protected void |
set(int col,
int row,
Player player)
Modifies the state of the game. |
protected void |
setWinner(Player player)
|
int |
squaresLeft()
|
protected void |
swapTurn()
|
void |
test()
Some generic tests for both TicTacToe and Gomoku. |
java.lang.String |
toString()
A plain ascii representation of the game, mainly for debugging purposes. |
Player |
winner()
|
Methods inherited from class java.util.Observable |
addObserver,
clearChanged,
countObservers,
deleteObserver,
deleteObservers,
hasChanged,
notifyObservers,
notifyObservers,
setChanged |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected Player[][] _gameState
protected int _rows
protected int _cols
protected int _winningScore
protected final Player _nobody
protected Player _winner
protected Player[] _player
protected int _turn
protected int _squaresLeft
Constructor Detail |
public AbstractBoardGame()
Method Detail |
protected void init(int cols, int rows, int score, Player playerX, Player playerO)
cols
- the number of columnsrows
- the number of rowsscore
- the winning score (3 for TicTacToe; 5 for Gomoku)playerX
- the player whose mark is 'X'playerO
- the player whose mark is 'Y'protected void initFailed(AssertionException err)
public void addObserver(RemoteObserver remote)
public int cols()
public int rows()
protected void set(int col, int row, Player player) throws AssertionException
col
- the columnrow
- the rowplayer
- the Player attempting the movepublic Player get(int col, int row) throws AssertionException
tictactoe.Runner#samePlayer
public Player currentPlayer()
public Player player(int n)
public void move(int col, int row, Player p) throws AssertionException
StreamPlayer.move()
protected void swapTurn()
public Player winner()
public boolean notOver()
public int squaresLeft()
protected void checkWinner(int col, int row) throws AssertionException
col
- the column of the current moverow
- the row of the current moveprotected void setWinner(Player player)
public java.lang.String toString()
public boolean inRange(int col, int row)
protected void assert(boolean assertion) throws AssertionException
public void test()
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |