Class LadderGameController
java.lang.Object
edu.ntnu.idi.idatt.controller.common.GameController
edu.ntnu.idi.idatt.controller.laddergame.LadderGameController
- All Implemented Interfaces:
BoardGameObserver
,ButtonClickObserver
LadderGameController.
This class extends GameController
to manage the specific logic and interactions
for a LadderBoardGame
. It acts as a controller in the MVC pattern, mediating between the
LadderGameView
(the view) and the LadderBoardGame
(the model).
Responsibilities include:
- Initializing the
LadderBoardGame
with a givenBoard
and list ofPlayer
s. - Handling player turns, including dice rolling (with animation) and executing moves on the game board.
- Updating the
LadderGameView
in response to game state changes, such as player movement, tile actions, round progression, current player changes, and game completion. - Processing user interactions from the view, like clicking the "roll dice", "restart game", or "quit game" buttons.
- Managing the display of player information (e.g., current tile) and game log entries.
- See Also:
-
Field Summary
Fields inherited from class edu.ntnu.idi.idatt.controller.common.GameController
boardGame, gameFinishedParams, gameView, logger, onNavigateToGameFinished, onQuitGame
-
Constructor Summary
ConstructorsConstructorDescriptionLadderGameController
(LadderGameView ladderGameView, Board board, List<Player> players) Constructs a newLadderGameController
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
initializeBoardGame
(Board board, List<Player> players) Initializes theGameController.boardGame
instance as aLadderBoardGame
.void
onButtonClicked
(String buttonId) Handles button click events from theLadderGameView
.void
onButtonClickedWithParams
(String buttonId, Map<String, Object> params) Handles button click events that may include parameters.void
onCurrentPlayerChanged
(Player player) Handles thecurrentPlayerChanged
event from theLadderBoardGame
model.void
onGameFinished
(Player winner) Handles thegameFinished
event from theLadderBoardGame
model.void
onPlayerMoved
(Player player, int diceRoll, int newTileId) Handles theplayerMoved
event from theLadderBoardGame
model.void
onRoundNumberIncremented
(int roundNumber) Handles theroundNumberIncremented
event from theLadderBoardGame
model.void
onTileActionPerformed
(Player player, TileAction tileAction) Handles thetileActionPerformed
event from theLadderBoardGame
model.protected void
Executes a single turn for the current player in theLadderBoardGame
.protected void
Performs turns for all players sequentially until it is the first player's turn again.protected void
Restarts the current game.Methods inherited from class edu.ntnu.idi.idatt.controller.common.GameController
disableRollDiceButton, enableRollDiceButton, getBoard, getPlayers, getRoundNumber, handleRollDiceButtonAction, initializeGameView, navigateToGameFinished, quitGame, setOnNavigateToGameFinished, setOnQuitGame
-
Constructor Details
-
LadderGameController
Constructs a newLadderGameController
.- Parameters:
ladderGameView
- TheLadderGameView
associated with this controller.board
- TheBoard
(specifically aLadderGameBoard
) for the game.players
- The list ofPlayer
s participating in the game.
-
-
Method Details
-
initializeBoardGame
Initializes theGameController.boardGame
instance as aLadderBoardGame
. It creates a new game with the provided board and players, and sets the number of dice to 2. This controller is also added as an observer to the newly created game model. All players are initially placed on the starting tile (tile 0).- Specified by:
initializeBoardGame
in classGameController
- Parameters:
board
- TheBoard
for the game.players
- The list ofPlayer
s.
-
performPlayerTurn
protected void performPlayerTurn()Executes a single turn for the current player in theLadderBoardGame
. This involves:- Disabling the roll dice button in the view.
- Simulating a dice roll in the
LadderBoardGame
. - Retrieving the individual dice values.
- Triggering an animation for the dice roll in the
LadderGameView
. - Upon completion of the animation, performing the player's turn in the game model using the total dice roll.
- Re-enabling the roll dice button.
- Specified by:
performPlayerTurn
in classGameController
-
performPlayerTurnForAllPlayers
protected void performPlayerTurnForAllPlayers()Performs turns for all players sequentially until it is the first player's turn again. This is typically used when the "roll for all players" option is active.- Specified by:
performPlayerTurnForAllPlayers
in classGameController
-
restartGame
protected void restartGame()Restarts the current game. This involves:- Creating a new list of
LadderGamePlayer
s based on the existing players (preserving their names, colors, token types, and bot status). - Re-initializing the
GameController.boardGame
with the same board but the new list of player instances. - Re-initializing the
LadderGameView
to reflect the new game state.
- Specified by:
restartGame
in classGameController
- Creating a new list of
-
onPlayerMoved
Handles theplayerMoved
event from theLadderBoardGame
model. Updates the game log in the view with the player's move, updates the player's displayed tile number, and triggers the visual movement of the player's token on theLadderGameStackPane
.- Parameters:
player
- ThePlayer
who moved.diceRoll
- The result of the dice roll that caused the move.newTileId
- The ID of the tile the player moved to.
-
onRoundNumberIncremented
public void onRoundNumberIncremented(int roundNumber) Handles theroundNumberIncremented
event from theLadderBoardGame
model. Updates the displayed round number in the view's player information panel and adds a new round entry to the game log.- Specified by:
onRoundNumberIncremented
in interfaceBoardGameObserver
- Specified by:
onRoundNumberIncremented
in classGameController
- Parameters:
roundNumber
- The new round number.
-
onCurrentPlayerChanged
Handles thecurrentPlayerChanged
event from theLadderBoardGame
model. If "roll for all players" is not selected, it sets the focus on the current player in the view's player information panel. If the new current player is a bot and "roll for all" is not active, it automatically performs the bot's turn. If "roll for all players" is selected, focus is removed from any specific player.- Specified by:
onCurrentPlayerChanged
in interfaceBoardGameObserver
- Specified by:
onCurrentPlayerChanged
in classGameController
- Parameters:
player
- The new currentPlayer
.
-
onTileActionPerformed
Handles thetileActionPerformed
event from theLadderBoardGame
model. This occurs when a player lands on a tile with a special action (e.g., ladder, slide). Updates the game log with the action, updates the player's displayed tile number to the destination of the action, and triggers the visual movement of the player's token on theLadderGameStackPane
to the action's destination tile.- Parameters:
player
- ThePlayer
who activated the tile action.tileAction
- TheTileAction
that was performed.
-
onGameFinished
Handles thegameFinished
event from theLadderBoardGame
model. Navigates to the GameFinishedView, passing the winner and other ranked players.- Specified by:
onGameFinished
in interfaceBoardGameObserver
- Specified by:
onGameFinished
in classGameController
- Parameters:
winner
- ThePlayer
who won the game.
-
onButtonClicked
Handles button click events from theLadderGameView
. Delegates actions based on the button ID:- "roll_dice": Calls
GameController.handleRollDiceButtonAction()
. - "restart_game": Calls
restartGame()
. - "quit_game": Calls
GameController.quitGame()
.
- Specified by:
onButtonClicked
in interfaceButtonClickObserver
- Specified by:
onButtonClicked
in classGameController
- Parameters:
buttonId
- The ID of the button that was clicked.
- "roll_dice": Calls
-
onButtonClickedWithParams
Handles button click events that may include parameters. This method is not currently used inLadderGameController
.- Specified by:
onButtonClickedWithParams
in interfaceButtonClickObserver
- Specified by:
onButtonClickedWithParams
in classGameController
- Parameters:
buttonId
- The ID of the clicked button.params
- A map of parameters associated with the button click.
-