|
|||||||||
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 |
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()
|
int |
get_cols()
|
int |
get_rows()
|
Player |
get(int col,
int row)
|
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. |
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 ... |
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()
|
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 |
Methods inherited from interface p2.tictactoe.BoardGame |
---|
addObserver |
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_
Constructor Detail |
---|
public AbstractBoardGame(Player playerX, Player playerO)
Method Detail |
---|
protected abstract void init()
public int get_cols()
get_cols
in interface BoardGame
public int get_rows()
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)
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()
currentPlayer
in interface BoardGame
public Player winner()
winner
in interface BoardGame
public int squaresLeft()
squaresLeft
in interface BoardGame
protected void swapTurn()
protected void checkWinner(int col, int row)
protected void setWinner(Player player)
protected boolean invariant()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |