Class LadderBoardGame

java.lang.Object
edu.ntnu.idi.idatt.model.game.BoardGame
edu.ntnu.idi.idatt.model.game.LadderBoardGame
All Implemented Interfaces:
Game, BoardGameSubject

public class LadderBoardGame extends BoardGame
LadderBoardGame.

Represents the game logic for a Chutes and Ladders type game. This class extends BoardGame and implements game-specific rules for player movement, tile actions (ladders/slides), and win conditions.

See Also:
  • Constructor Details

    • LadderBoardGame

      public LadderBoardGame(Board board, List<Player> players, int diceCount)
      Constructs a LadderBoardGame.
      Parameters:
      board - The Board instance for this game.
      players - A list of Players (expected to be LadderGamePlayer instances).
      diceCount - The number of dice to be used in the game.
  • Method Details

    • initializeGame

      public void initializeGame()
      Initializes the game state. Places all players on the starting tile (tile 0) and sets the first player in the list as the current player.
      Specified by:
      initializeGame in interface Game
      Specified by:
      initializeGame in class BoardGame
    • getWinner

      public Player getWinner()
      Determines the winner of the game. A player wins if their current tile ID is equal to the total number of tiles on the board.
      Returns:
      The winning Player, or null if no player has won yet.
    • rollDice

      public int rollDice()
      Rolls all dice in the game and returns their total value.
      Returns:
      The sum of values from all rolled dice.
    • performPlayerTurn

      public void performPlayerTurn(int diceRoll)
      Performs a complete turn for the current player based on a dice roll. This involves moving the player, handling any tile action (ladder/slide), checking for a win condition, updating to the next player, and handling the round number.
      Parameters:
      diceRoll - The total value rolled on the dice.
    • handleTileAction

      protected void handleTileAction()
      Checks if the current player has landed on a tile with a TileAction (ladder or slide). If an action exists, it is performed, and observers are notified.
    • movePlayer

      public void movePlayer(int diceRoll)
      Moves the current player based on the provided dice roll value. Finds the next tile using findNextTile(Player, int) and updates the player's position. Notifies observers of the player movement.
      Parameters:
      diceRoll - The total value rolled on the dice.
    • notifyTileActionPerformed

      public void notifyTileActionPerformed(Player player, TileAction tileAction)
      Notifies registered observers (specifically LadderGameController instances) that a tile action has been performed.
      Parameters:
      player - The Player who triggered the action.
      tileAction - The TileAction that was performed.