Package edu.ntnu.idi.idatt.model.game
Class LadderBoardGame
java.lang.Object
edu.ntnu.idi.idatt.model.game.BoardGame
edu.ntnu.idi.idatt.model.game.LadderBoardGame
- All Implemented Interfaces:
Game
,BoardGameSubject
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:
-
Field Summary
Fields inherited from class edu.ntnu.idi.idatt.model.game.BoardGame
board, currentPlayer, dice, logger, observers, players, roundNumber
-
Constructor Summary
ConstructorsConstructorDescriptionLadderBoardGame
(Board board, List<Player> players, int diceCount) Constructs a LadderBoardGame. -
Method Summary
Modifier and TypeMethodDescriptionDetermines the winner of the game.protected void
Checks if the current player has landed on a tile with aTileAction
(ladder or slide).void
Initializes the game state.void
movePlayer
(int diceRoll) Moves the current player based on the provided dice roll value.void
notifyTileActionPerformed
(Player player, TileAction tileAction) Notifies registered observers (specificallyLadderGameController
instances) that a tile action has been performed.void
performPlayerTurn
(int diceRoll) Performs a complete turn for the current player based on a dice roll.int
rollDice()
Rolls all dice in the game and returns their total value.Methods inherited from class edu.ntnu.idi.idatt.model.game.BoardGame
addObserver, checkWinCondition, createDice, getBoard, getCurrentPlayer, getDice, getPlayers, getRoundNumber, handleRoundNumber, incrementRoundNumber, notifyCurrentPlayerChanged, notifyGameFinished, notifyRoundNumberIncremented, removeObserver, setBoard, setCurrentPlayer, setPlayers, updateCurrentPlayer
-
Constructor Details
-
LadderBoardGame
Constructs a LadderBoardGame.- Parameters:
board
- TheBoard
instance for this game.players
- A list ofPlayer
s (expected to beLadderGamePlayer
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 interfaceGame
- Specified by:
initializeGame
in classBoardGame
-
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 aTileAction
(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 usingfindNextTile(Player, int)
and updates the player's position. Notifies observers of the player movement.- Parameters:
diceRoll
- The total value rolled on the dice.
-
notifyTileActionPerformed
Notifies registered observers (specificallyLadderGameController
instances) that a tile action has been performed.- Parameters:
player
- ThePlayer
who triggered the action.tileAction
- TheTileAction
that was performed.
-