|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Observable
p2.tictactoe.AbstractBoardGame
public abstract class AbstractBoardGame
AbstractBoardGame implements common methods to TicTacToe and Gomoku.
Field Summary | |
---|---|
protected int |
cols_
|
protected Player[][] |
gameState_
|
protected Player |
nobody_
|
protected Player[] |
player_
|
protected int |
rows_
|
protected int |
squaresLeft_
|
protected int |
toJoin_
|
protected int |
turn_
|
protected Player |
winner_
|
protected int |
winningScore_
|
Constructor Summary | |
---|---|
AbstractBoardGame(Player playerX,
Player playerO)
The state of the game is represented as 3x3 array of chars marked ' ', 'X', or 'O'. |
Method Summary | |
---|---|
protected void |
checkWinner(int col,
int row)
New algorithm needed for larger boards. |
Player |
currentPlayer()
Returns which Player must play now. |
int |
get_cols()
Number of columns in this game. |
int |
get_rows()
Number of rows in this game. |
Player |
get(int col,
int row)
Returns the Player who has played at the given position. |
protected abstract void |
init()
Subclasses should initialize _rows, _cols and _winningScore |
boolean |
inRange(int col,
int row)
Needed for getter and setter preconditions. |
protected boolean |
invariant()
These seem obvious, which is exactly why they should be checked. |
Player |
join()
Must be called twice, once for each Player. |
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 ... |
boolean |
ready()
Two Players have joined. |
void |
restart()
(Re-)initialize the game state. |
protected void |
set(int col,
int row,
Player player)
Modifies the state of the game. |
protected void |
setWinner(Player player)
|
int |
squaresLeft()
The number of squares left unplayed. |
protected void |
swapTurn()
|
java.lang.String |
toString()
A plain ascii representation of the game, mainly for debugging purposes. |
Player |
winner()
Returns the winner of the game. |
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 |
Methods inherited from interface p2.tictactoe.BoardGame |
---|
addObserver, name |
Field Detail |
---|
protected int rows_
protected int cols_
protected int winningScore_
protected Player[][] gameState_
protected final Player nobody_
protected Player winner_
protected Player[] player_
protected int turn_
protected int squaresLeft_
protected int toJoin_
Constructor Detail |
---|
public AbstractBoardGame(Player playerX, Player playerO)
Method Detail |
---|
protected abstract void init()
public Player join()
join
in interface BoardGame
public boolean ready()
ready
in interface BoardGame
public int get_cols()
BoardGame
get_cols
in interface BoardGame
public int get_rows()
BoardGame
get_rows
in interface BoardGame
protected void set(int col, int row, Player player)
col
- the columnrow
- the rowplayer
- the Player attempting the movepublic Player get(int col, int row)
BoardGame
get
in interface BoardGame
public boolean notOver()
notOver
in interface BoardGame
public java.lang.String toString()
toString
in class java.lang.Object
public boolean inRange(int col, int row)
inRange
in interface BoardGame
public void move(int col, int row, Player p) throws InvalidMoveException
move
in interface BoardGame
InvalidMoveException
public Player currentPlayer()
BoardGame
currentPlayer
in interface BoardGame
public Player winner()
BoardGame
winner
in interface BoardGame
public int squaresLeft()
BoardGame
squaresLeft
in interface BoardGame
protected void swapTurn()
protected void checkWinner(int col, int row)
protected void setWinner(Player player)
protected boolean invariant()
public void restart()
restart
in interface BoardGame
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |