Package be.belegkarnil.game.board.tak
Class Game
java.lang.Object
be.belegkarnil.game.board.tak.Game
- All Implemented Interfaces:
Runnable
The class implements the behavior of the Spectrangle game (a modified two players version with skip and penalities)
- Author:
- Belegkarnil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumIs an enumeration that express all the winning reasons -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intis the number of rounds to win in order to win the whole gamestatic final intis the maximum of allowed skip before considering to stop the gamestatic final intis the scoring penalty if a player can put aPiecebut he does notstatic final intis the default maximum number of seconds that each players has per turn -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a game with default settings (DEFAULT_TIMEOUT,DEFAULT_NUMBER_OF_WINNING_ROUNDS,DEFAULT_SKIP_LIMIT, andDEFAULT_SKIP_PENALTY)Game(Board board, Player player1, Player player2, int timeout, int numWinningRounds, int skipLimit, int skipPenality) Construct a game with custom settings -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGameListener(GameListener listener) Register aGameListenerto forward allGameEventvoidaddMisdesignListener(MisdesignListener listener) Register aMisdesignListenerto forward allMisdesignEventvoidaddRoundListener(RoundListener listener) Register aRoundListenerto forward allRoundEventvoidaddTurnListener(TurnListener listener) Register aTurnListenerto forward allTurnEventstatic booleanprotected voidExecute the game mechanic: handle events, rounds, turns, scoring, and playersprotected voidExecute the game mechanic of a single round: handle events, turns, scoring, and playersprotected voidExecute the game mechanic of a single turn: handle events, scoring, and playersprotected voidfireException(MisdesignEvent event) Send an event on allMisdesignListener, callingMisdesignListener.onException(MisdesignEvent)protected voidfireGameBegins(GameEvent event) Send an event on allGameListener, callingGameListener.onGameBegins(GameEvent)protected voidfireGameEnds(GameEvent event) Send an event on allGameListener, callingGameListener.onGameEnds(GameEvent)protected voidfireInvalidAction(MisdesignEvent event) Send an event on allMisdesignListener, callingMisdesignListener.onInvalidAction(MisdesignEvent)protected voidfireInvalidPiece(MisdesignEvent event) Send an event on allMisdesignListener, callingMisdesignListener.onInvalidPiece(MisdesignEvent)protected voidfireRoundBegins(RoundEvent event) Send an event on allRoundListener, callingRoundListener.onRoundBegins(RoundEvent)protected voidfireRoundEnds(RoundEvent event) Send an event on allRoundListener, callingRoundListener.onRoundEnds(RoundEvent)protected voidfireTimeout(MisdesignEvent event) Send an event on allMisdesignListener, callingMisdesignListener.onTimeout(MisdesignEvent)protected voidfireTurnBegins(TurnEvent event) Send an event on allTurnListener, callingTurnListener.onTurnBegins(TurnEvent)protected voidfireTurnEnds(TurnEvent event) Send an event on allTurnListener, callingTurnListener.onTurnEnds(TurnEvent)getBoard()Get the current board used by the running gameGet the first player involved in the gameintgetRound()Get the current round identifier (counter)Get the second player involved in the gameintGet the number of skip turns to stop the gameintGet the number of second a player has to select anActionintgetTurn()Get the current turn identifier (counter)intGet the number of rounds to be won in order to win the gamevoidremoveGameListener(GameListener listener) Unregister aGameListenerto stop forwardingGameEventvoidremoveMisdesignListener(MisdesignListener listener) Unregister aMisdesignListenerto stop forwardingMisdesignEventvoidremoveRoundListener(RoundListener listener) Unregister aRoundListenerto stop forwardingRoundEventvoidremoveTurnListener(TurnListener listener) Unregister aTurnListenerto stop forwardingTurnEventvoidrun()is the method called by the JavaThreadmechanism which consist only in callingexecuteGame()
-
Field Details
-
DEFAULT_SKIP_LIMIT
public static final int DEFAULT_SKIP_LIMITis the maximum of allowed skip before considering to stop the game- See Also:
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUTis the default maximum number of seconds that each players has per turn- See Also:
-
DEFAULT_NUMBER_OF_WINNING_ROUNDS
public static final int DEFAULT_NUMBER_OF_WINNING_ROUNDSis the number of rounds to win in order to win the whole game- See Also:
-
DEFAULT_SKIP_PENALTY
public static final int DEFAULT_SKIP_PENALTYis the scoring penalty if a player can put aPiecebut he does not- See Also:
-
-
Constructor Details
-
Game
Construct a game with default settings (DEFAULT_TIMEOUT,DEFAULT_NUMBER_OF_WINNING_ROUNDS,DEFAULT_SKIP_LIMIT, andDEFAULT_SKIP_PENALTY)- Parameters:
board- The board that the game will useplayer1- The first player involved in the gameplayer2- The second player involved in the game
-
Game
public Game(Board board, Player player1, Player player2, int timeout, int numWinningRounds, int skipLimit, int skipPenality) Construct a game with custom settings- Parameters:
board- The board that the game will useplayer1- The first player involved in the gameplayer2- The second player involved in the gametimeout- The custom timeout settings (time in seconds a player has per turn)numWinningRounds- The number of rounds has to win in order to win the gameskipLimit- The number of skip turns before to stop the gameskipPenality- The scoring penality if a player can play but he does not
-
-
Method Details
-
getFirstPlayer
Get the first player involved in the game- Returns:
- the first player
-
getSecondPlayer
Get the second player involved in the game- Returns:
- the second player
-
getTimeout
public int getTimeout()Get the number of second a player has to select anAction- Returns:
- the number of seconds to define a timeout
-
getSkipLimit
public int getSkipLimit()Get the number of skip turns to stop the game- Returns:
- the number of skip turns
-
getWinningRounds
public int getWinningRounds()Get the number of rounds to be won in order to win the game- Returns:
- the number of winning rounds
-
getRound
public int getRound()Get the current round identifier (counter)- Returns:
- the round identifier
-
getTurn
public int getTurn()Get the current turn identifier (counter)- Returns:
- the turn identifier
-
executeTurn
protected void executeTurn()Execute the game mechanic of a single turn: handle events, scoring, and players -
canPlay
- Parameters:
board- the current game boardcurrent- the player to check if he can play- Returns:
- true iff the player can put at least one
Piece
-
executeRound
protected void executeRound()Execute the game mechanic of a single round: handle events, turns, scoring, and players -
executeGame
protected void executeGame()Execute the game mechanic: handle events, rounds, turns, scoring, and players -
run
public void run()is the method called by the JavaThreadmechanism which consist only in callingexecuteGame() -
fireTimeout
Send an event on allMisdesignListener, callingMisdesignListener.onTimeout(MisdesignEvent)- Parameters:
event- the event to send
-
fireException
Send an event on allMisdesignListener, callingMisdesignListener.onException(MisdesignEvent)- Parameters:
event- the event to send
-
fireInvalidAction
Send an event on allMisdesignListener, callingMisdesignListener.onInvalidAction(MisdesignEvent)- Parameters:
event- the event to send
-
fireInvalidPiece
Send an event on allMisdesignListener, callingMisdesignListener.onInvalidPiece(MisdesignEvent)- Parameters:
event- the event to send
-
fireGameBegins
Send an event on allGameListener, callingGameListener.onGameBegins(GameEvent)- Parameters:
event- the event to send
-
fireGameEnds
Send an event on allGameListener, callingGameListener.onGameEnds(GameEvent)- Parameters:
event- the event to send
-
fireRoundBegins
Send an event on allRoundListener, callingRoundListener.onRoundBegins(RoundEvent)- Parameters:
event- the event to send
-
fireRoundEnds
Send an event on allRoundListener, callingRoundListener.onRoundEnds(RoundEvent)- Parameters:
event- the event to send
-
fireTurnBegins
Send an event on allTurnListener, callingTurnListener.onTurnBegins(TurnEvent)- Parameters:
event- the event to send
-
fireTurnEnds
Send an event on allTurnListener, callingTurnListener.onTurnEnds(TurnEvent)- Parameters:
event- the event to send
-
addGameListener
Register aGameListenerto forward allGameEvent- Parameters:
listener- the listener that will receive events
-
removeGameListener
Unregister aGameListenerto stop forwardingGameEvent- Parameters:
listener- the listener that will no more receive events
-
addRoundListener
Register aRoundListenerto forward allRoundEvent- Parameters:
listener- the listener that will receive events
-
removeRoundListener
Unregister aRoundListenerto stop forwardingRoundEvent- Parameters:
listener- the listener that will no more receive events
-
addTurnListener
Register aTurnListenerto forward allTurnEvent- Parameters:
listener- the listener that will receive events
-
removeTurnListener
Unregister aTurnListenerto stop forwardingTurnEvent- Parameters:
listener- the listener that will no more receive events
-
addMisdesignListener
Register aMisdesignListenerto forward allMisdesignEvent- Parameters:
listener- the listener that will receive events
-
removeMisdesignListener
Unregister aMisdesignListenerto stop forwardingMisdesignEvent- Parameters:
listener- the listener that will no more receive events
-
getBoard
Get the current board used by the running game- Returns:
- the board used by the game
-