|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbluegammon.logic.Board
bluegammon.logic.BoardState
Singleton class holding game logic and state of a game. There can only be one state per device, thus the singleton pattern.
Extends the Board
class with player-, turn-, dice- and rule-logic.
The BoardState
is detached from gui. State reports when
pieces are moved etc can be retreived by implementing the
BoardStateListener
interface and registering this instance
in the BoardState
.
BoardMediator
Field Summary | |
static int |
PM_DEST
Possible move board destination index |
static int |
PM_DICE
Possible move dice value index |
static int |
PM_SOUR
Possible move board source index |
Fields inherited from class bluegammon.logic.Board |
MAX_POS, POS_BOARD, POS_GUARD, POS_OUT |
Method Summary | |
boolean |
areAllPiecesHome(boolean white)
Checks if there are any pieces outside home - in that case pieces must not be moved off the boards. |
void |
commitMove(boolean white,
int diceValue)
Commits a move, step (3) of performing a move. |
void |
consumeDice(int diceIndex)
Consumes a dice value, called when a player moves a piece. |
int |
countPossibleMoves(boolean white)
Returns number of possible moves for current game state. |
int |
countUndoableMoves()
Returns number of possible undoable moves |
Player |
getCurrentPlayer()
Returns current player. |
int |
getDiceValue(int diceIndex)
Returns value of specified dice |
static BoardState |
getInstance()
|
int[][] |
getPossibleMoves(boolean white)
Calculates possible moves and returns array, composed as int[possibleMoveIndex][PM_SOUR | PM_DEST | PM_DICE] where PM_SOUR denotes the source index, PM_DEST denotes the destination index, and PM_DICE denotes the dice value index that is used for the move. |
Player |
getWaitingPlayer()
Returns waiting player. |
boolean |
isCurrentPlayerWhite()
Returns the color of current player. |
boolean |
isGameFinished()
Returns whether the game is finished or not |
boolean |
isNoneBefore(boolean white,
int index)
Returns true if there are no pieces of specified color before specified index. |
int |
loadState(java.io.DataInputStream dis)
Loads state from specified input stream. |
void |
makeMove(int index,
int dest,
boolean white)
Moves a piece of specified color, from specified index to specified destination on board. |
void |
newDiceValues(int dice1,
int dice2)
Throws dices, and puts new values in the dice value vector. |
int |
saveState(java.io.DataOutputStream dos)
Saves current state to specified outputstream. |
void |
setCurrentPlayer(boolean white)
Sets the turn to the player having specified color without notifying listener about the change. |
void |
setGameFinished(boolean b)
Marks this game as finished |
void |
setGameListener(BoardStateListener listener)
Registers a boardstate-listener that will receive events upon state changes. |
void |
setPlayers(Player player1,
Player player2)
Defines the two backgammon players. |
void |
setTurn(boolean whiteTurn)
Sets the turn to the player having specified color and notifies listener about the change. |
int |
undoLastMove(boolean white)
Undoes the last move. |
Methods inherited from class bluegammon.logic.Board |
addPiece, calculatePiecesLeft, calculatePoints, countPieces, countPieces, getOpponentIndex, getPlayerIndex, isWhite, loadBoard, removePiece, saveBoard, setPieces, setStartPositions |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int PM_SOUR
public static final int PM_DEST
public static final int PM_DICE
Method Detail |
public void setGameListener(BoardStateListener listener)
listener
- The listener.public void setPlayers(Player player1, Player player2)
player1
- Player one.player2
- Player two.public boolean isGameFinished()
public void setGameFinished(boolean b)
b
- true for finished, false otherwisepublic boolean isCurrentPlayerWhite()
public Player getCurrentPlayer()
public Player getWaitingPlayer()
public void setCurrentPlayer(boolean white)
white
- True for white player, false for black playerpublic void setTurn(boolean whiteTurn)
whiteTurn
- True for white player, false for black playerpublic void makeMove(int index, int dest, boolean white)
index
- The source index to move fromdest
- The destination index to move towhite
- The color of the piece to movepublic void consumeDice(int diceIndex)
diceIndex
- The diceindex that was used for the move.public void commitMove(boolean white, int diceValue)
white
- The color of the pieces whose moves are to be commited.diceValue
- The dicevalue that was used for the move.public int undoLastMove(boolean white)
white
- The color of the player that undoes
public int[][] getPossibleMoves(boolean white)
countPossibleMoves()
white
- The color of the player
public int countPossibleMoves(boolean white)
getPossibleMoves
.
white
- The color of the player
public void newDiceValues(int dice1, int dice2)
dice1
- value of dice onedice2
- value of dice twopublic int getDiceValue(int diceIndex)
diceIndex
- the dice, 0 or 1
public int countUndoableMoves()
public boolean isNoneBefore(boolean white, int index)
white
- True for white, false for blackindex
- The index
public boolean areAllPiecesHome(boolean white)
white
- true to check if all white is home,
false to check if all black is home.
public int loadState(java.io.DataInputStream dis) throws java.io.IOException
saveState
for format.
dis
- the input stream
java.io.IOException
public int saveState(java.io.DataOutputStream dos) throws java.io.IOException
dos
- the output stream
java.io.IOException
public static BoardState getInstance()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |