|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbluegammon.logic.BoardMediator
The BoardMediator
class is active during a backgammon game. It takes care
of coordination between BoardState
and BoardCanvas
i.e.
between the gui and the logic. BoardCanvas
is detached from any
backgammon-logic - this connection is made by this class by implementing
BoardStateListener
to receive events upon board state changes. The
BoardMediator
then calls the BoardCanvas
to update the gui
when state changes.
In order to save the game at any time, but still have animations, the
BoardState
differs from the BoardCanvas
: when the state
is changed (e.g. a move is made), the BoardState
is updated
directly. The BoardCanvas
has intermittent states; e.g. during an animation
of a piece movement, one piece is "missing" from BoardCanvas
board until
the piece is put down.
This class is a simple coordinater, thus it does not have any state. The
BoardMediator
is accessed statically.
BoardCanvas
,
BoardState
Method Summary | |
static void |
commitTurn()
Called from interaction, commits players' moves. |
static int |
countPossibleMoves()
Returns number of possible moves based on current board state for player with current turn. |
static int |
countStatePieces(int index)
Returns number of pieces on specified index in current state. |
static int |
countUndoableMoves()
Returns number of possible undoable moves |
static void |
exitGame(int reason)
Called from interaction, exits current game. |
static void |
forceGameFinished()
Forces the game state to be finished. |
void |
gameFinished(boolean whiteWinner,
int loserPiecesLeft,
int points)
Called from BoardState when a game is finished |
static BoardCanvas |
getCanvas()
Returns the boardcanvas singleton instance. |
static Player |
getCurrentPlayer()
Returns the player whos holding the turn, i.e. can make moves. |
static int |
getDiceValue(int index)
Returns value of specified dice |
static LocalPlayer |
getLocalPlayer()
Returns the one LocalPlayer . |
static Player |
getOpponentPlayer()
Returns opponent player. |
static int[][] |
getPossibleMoves()
Returns possible moves based on current board state. |
static void |
init(Player p1,
Player p2,
boolean resumed)
Initiates a new or resumed game with specified players. |
static boolean |
isCurrentPlayerWhite()
Returns the color of current player. |
static boolean |
isGameFinished()
Returns whether the game is finished or not |
static boolean |
isRemoteTurn()
Returns whether the current turn belongs to a remote player or not. |
static void |
loadGame(java.io.InputStream is,
boolean flipColors)
Loads a saved game from specified input stream. |
static void |
lostRemoteConnection(java.io.IOException e)
Called from IO framework remote connection is lost in a remote game. |
static void |
makePlayerMove(int possibleMoveIndex)
Called from interaction, moves a player piece. |
static int |
newDiceValue()
Returns a new dice value, a random integer between 1 and 6. |
static void |
newTurn(boolean whiteTurn)
Called from interaction and logic, changes turn. |
void |
pieceMoved(boolean white,
int from,
int to)
Called from BoardState whenever a piece is moved. |
static int |
saveGame(java.io.OutputStream os)
Saves current game to specified output stream. |
static void |
showMessage(char[] mess)
Called when remote player sent a message |
static void |
shutdown()
Shuts the BoardMediator down. |
static void |
startup()
Starts the BoardMediator. |
void |
turnChange(boolean whiteTurn)
Called from BoardState when turn changes. |
void |
undoAdded(int undos,
int diceValue)
Called from BoardState when a possible undo has been added |
static void |
undoLastMove()
Called from interaction, undoes the last move. |
void |
undoPerformed(int undos,
int diceValue)
Called from BoardState when an undo is performed. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static void startup()
public static void init(Player p1, Player p2, boolean resumed)
p1
- Player 1.p2
- Player 2.resumed
- True if resumed, false if new game.public static void shutdown()
public static void makePlayerMove(int possibleMoveIndex)
possibleMoveIndex
- How to move according to current BoardStatepublic static void undoLastMove()
public static void commitTurn()
public static void newTurn(boolean whiteTurn)
whiteTurn
- true if turn changes to white player, false otherwise.public static void exitGame(int reason)
reason
- An integer denoting the reason for quitting,
one of PlayerListener.LOCAL_QUIT
,
PlayerListener.REMOTE_QUIT,
PlayerListener.LOCAL_GIVE_UP,
PlayerListener.REMOTE_GIVE_UP
public static void lostRemoteConnection(java.io.IOException e)
e
- The exception that was
the reason of losing connection.public static void showMessage(char[] mess)
mess
- the message.public static Player getCurrentPlayer()
public static Player getOpponentPlayer()
public static LocalPlayer getLocalPlayer()
LocalPlayer
. If the game is local,
arbitrary LocalPlayer
is returned. This method only makes
sense in remote games.
LocalPlayer
in the game.public static boolean isRemoteTurn()
public static int[][] getPossibleMoves()
BoardState.getPossibleMoves(boolean)
public static int countPossibleMoves()
public static boolean isGameFinished()
public static void forceGameFinished()
public static int countUndoableMoves()
public static int newDiceValue()
public static int getDiceValue(int index)
index
- the dice, 0 or 1
public static int countStatePieces(int index)
index
- The board index
public static BoardCanvas getCanvas()
public static void loadGame(java.io.InputStream is, boolean flipColors) throws java.io.IOException
is
- The input stream to load saved game data from.flipColors
- Flag indicating if the colors of the players
should be flipped according to what is specified
in the saved game data.
java.io.IOException
- If error occurs when loading data.public static int saveGame(java.io.OutputStream os) throws java.io.IOException
os
- The output stream to write saved game data to.
java.io.IOException
- If error occurs when writing saved game data.public static boolean isCurrentPlayerWhite()
public void turnChange(boolean whiteTurn)
BoardStateListener
turnChange
in interface BoardStateListener
whiteTurn
- true if white turn, false if black.public void pieceMoved(boolean white, int from, int to)
BoardStateListener
pieceMoved
in interface BoardStateListener
white
- true if white piece, false otherwisefrom
- piece source indexto
- piece destination indexpublic void undoAdded(int undos, int diceValue)
BoardStateListener
undoAdded
in interface BoardStateListener
undos
- Number of current undosdiceValue
- The dice value that can be used for undo (1-6)public void undoPerformed(int undos, int diceValue)
BoardStateListener
undoPerformed
in interface BoardStateListener
undos
- Number of current undosdiceValue
- The dice value that was used for undo (1-6)public void gameFinished(boolean whiteWinner, int loserPiecesLeft, int points)
BoardStateListener
gameFinished
in interface BoardStateListener
whiteWinner
- True if white player wins, false if black player winsloserPiecesLeft
- Total number of loser pieces leftpoints
- Point per piece
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |