Class Game

java.lang.Object
be.belegkarnil.game.board.tak.Game
All Implemented Interfaces:
Runnable

public class Game extends Object implements Runnable
The class implements the behavior of the Spectrangle game (a modified two players version with skip and penalities)
Author:
Belegkarnil
  • Field Details

    • DEFAULT_SKIP_LIMIT

      public static final int DEFAULT_SKIP_LIMIT
      is the maximum of allowed skip before considering to stop the game
      See Also:
    • DEFAULT_TIMEOUT

      public static final int DEFAULT_TIMEOUT
      is 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_ROUNDS
      is the number of rounds to win in order to win the whole game
      See Also:
    • DEFAULT_SKIP_PENALTY

      public static final int DEFAULT_SKIP_PENALTY
      is the scoring penalty if a player can put a Piece but he does not
      See Also:
  • Constructor Details

    • Game

      public Game(Board board, Player player1, Player player2)
      Parameters:
      board - The board that the game will use
      player1 - The first player involved in the game
      player2 - 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 use
      player1 - The first player involved in the game
      player2 - The second player involved in the game
      timeout - 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 game
      skipLimit - The number of skip turns before to stop the game
      skipPenality - The scoring penality if a player can play but he does not
  • Method Details

    • getFirstPlayer

      public Player getFirstPlayer()
      Get the first player involved in the game
      Returns:
      the first player
    • getSecondPlayer

      public 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 an Action
      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

      public static boolean canPlay(Board board, Player current)
      Check if a player has a Piece to play on the game Board
      Parameters:
      board - the current game board
      current - 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 Java Thread mechanism which consist only in calling executeGame()
      Specified by:
      run in interface Runnable
    • fireTimeout

      protected void fireTimeout(MisdesignEvent event)
      Parameters:
      event - the event to send
    • fireException

      protected void fireException(MisdesignEvent event)
      Parameters:
      event - the event to send
    • fireInvalidAction

      protected void fireInvalidAction(MisdesignEvent event)
      Parameters:
      event - the event to send
    • fireInvalidPiece

      protected void fireInvalidPiece(MisdesignEvent event)
      Parameters:
      event - the event to send
    • fireGameBegins

      protected void fireGameBegins(GameEvent event)
      Parameters:
      event - the event to send
    • fireGameEnds

      protected void fireGameEnds(GameEvent event)
      Send an event on all GameListener, calling GameListener.onGameEnds(GameEvent)
      Parameters:
      event - the event to send
    • fireRoundBegins

      protected void fireRoundBegins(RoundEvent event)
      Parameters:
      event - the event to send
    • fireRoundEnds

      protected void fireRoundEnds(RoundEvent event)
      Parameters:
      event - the event to send
    • fireTurnBegins

      protected void fireTurnBegins(TurnEvent event)
      Parameters:
      event - the event to send
    • fireTurnEnds

      protected void fireTurnEnds(TurnEvent event)
      Send an event on all TurnListener, calling TurnListener.onTurnEnds(TurnEvent)
      Parameters:
      event - the event to send
    • addGameListener

      public void addGameListener(GameListener listener)
      Register a GameListener to forward all GameEvent
      Parameters:
      listener - the listener that will receive events
    • removeGameListener

      public void removeGameListener(GameListener listener)
      Unregister a GameListener to stop forwarding GameEvent
      Parameters:
      listener - the listener that will no more receive events
    • addRoundListener

      public void addRoundListener(RoundListener listener)
      Register a RoundListener to forward all RoundEvent
      Parameters:
      listener - the listener that will receive events
    • removeRoundListener

      public void removeRoundListener(RoundListener listener)
      Unregister a RoundListener to stop forwarding RoundEvent
      Parameters:
      listener - the listener that will no more receive events
    • addTurnListener

      public void addTurnListener(TurnListener listener)
      Register a TurnListener to forward all TurnEvent
      Parameters:
      listener - the listener that will receive events
    • removeTurnListener

      public void removeTurnListener(TurnListener listener)
      Unregister a TurnListener to stop forwarding TurnEvent
      Parameters:
      listener - the listener that will no more receive events
    • addMisdesignListener

      public void addMisdesignListener(MisdesignListener listener)
      Register a MisdesignListener to forward all MisdesignEvent
      Parameters:
      listener - the listener that will receive events
    • removeMisdesignListener

      public void removeMisdesignListener(MisdesignListener listener)
      Unregister a MisdesignListener to stop forwarding MisdesignEvent
      Parameters:
      listener - the listener that will no more receive events
    • getBoard

      public Board getBoard()
      Get the current board used by the running game
      Returns:
      the board used by the game