Package edu.ntnu.idi.idatt.model.game
Class BoardGame
java.lang.Object
edu.ntnu.idi.idatt.model.game.BoardGame
- All Implemented Interfaces:
Game
,BoardGameSubject
- Direct Known Subclasses:
LadderBoardGame
,LudoBoardGame
BoardGame class
Abstract class implementing common functionality for board games. This class provides the base implementation for both Chutes and Ladders and Ludo games.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Board
protected Player
protected Dice
protected static final org.slf4j.Logger
protected final List
<BoardGameObserver> protected int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addObserver
(BoardGameObserver observer) Adds an observer to be notified of game events.protected void
Checks if a win condition has been met.protected void
createDice
(int diceCount) Creates the dice to be used in the game.getBoard()
Gets the game board.Gets the current player.getDice()
Gets the game dice.Gets all players in the game.int
Gets the current round number.void
Handles the progression of game rounds.protected void
Increments the round number and notifies observers.abstract void
Initializes the game by setting the initial state of the game.void
notifyCurrentPlayerChanged
(Player player) Notifies all registered observers that the current player has changed.void
notifyGameFinished
(Player winner) Notifies all registered observers that the game has finished.void
notifyRoundNumberIncremented
(int roundNumber) Notifies all registered observers that the round number has incremented.void
removeObserver
(BoardGameObserver observer) Removes an observer from the list of observers.void
Sets the game board.void
setCurrentPlayer
(Player player) Sets the current player.void
setPlayers
(List<Player> players) Sets the list of players for the game.protected void
Updates the current player to the next player in the turn order and notifies observers of the change.
-
Field Details
-
logger
protected static final org.slf4j.Logger logger -
observers
-
board
-
players
-
currentPlayer
-
dice
-
roundNumber
protected int roundNumber
-
-
Constructor Details
-
BoardGame
Constructor for BoardGame.- Parameters:
board
- The game boardplayers
- The list of playersdiceCount
- The number of dice to use
-
-
Method Details
-
initializeGame
public abstract void initializeGame()Initializes the game by setting the initial state of the game. This method is implemented by the subclasses to define game-specific setup, such as placing pieces, determining the starting player, or configuring initial game parameters.- Specified by:
initializeGame
in interfaceGame
-
getBoard
Description copied from interface:Game
Gets the game board. -
getDice
Description copied from interface:Game
Gets the game dice. -
getPlayers
Description copied from interface:Game
Gets all players in the game.- Specified by:
getPlayers
in interfaceGame
- Returns:
- list of all players
-
getCurrentPlayer
Description copied from interface:Game
Gets the current player.- Specified by:
getCurrentPlayer
in interfaceGame
- Returns:
- the current player
-
getRoundNumber
public int getRoundNumber()Description copied from interface:Game
Gets the current round number.- Specified by:
getRoundNumber
in interfaceGame
- Returns:
- the current round number
-
setBoard
Sets the game board. -
setPlayers
Sets the list of players for the game.- Specified by:
setPlayers
in interfaceGame
- Parameters:
players
- A list ofPlayer
objects participating in the game.
-
setCurrentPlayer
Sets the current player.- Specified by:
setCurrentPlayer
in interfaceGame
- Parameters:
player
- The player to set as current
-
addObserver
Adds an observer to be notified of game events.- Specified by:
addObserver
in interfaceBoardGameSubject
- Parameters:
observer
- TheBoardGameObserver
to add.
-
removeObserver
Removes an observer from the list of observers.- Specified by:
removeObserver
in interfaceBoardGameSubject
- Parameters:
observer
- TheBoardGameObserver
to remove.
-
handleRoundNumber
public void handleRoundNumber()Handles the progression of game rounds. This involves checking if the current player is the first player in the turn order, and if so, incrementing the round number.- Specified by:
handleRoundNumber
in interfaceGame
-
incrementRoundNumber
protected void incrementRoundNumber()Increments the round number and notifies observers. -
createDice
protected void createDice(int diceCount) Creates the dice to be used in the game.- Parameters:
diceCount
- The number of dice to create.
-
updateCurrentPlayer
protected void updateCurrentPlayer()Updates the current player to the next player in the turn order and notifies observers of the change. -
checkWinCondition
protected void checkWinCondition()Checks if a win condition has been met. If a winner is found, it notifies observers that the game has finished. -
notifyRoundNumberIncremented
public void notifyRoundNumberIncremented(int roundNumber) Notifies all registered observers that the round number has incremented.- Specified by:
notifyRoundNumberIncremented
in interfaceBoardGameSubject
- Parameters:
roundNumber
- The new round number.
-
notifyCurrentPlayerChanged
Notifies all registered observers that the current player has changed.- Specified by:
notifyCurrentPlayerChanged
in interfaceBoardGameSubject
- Parameters:
player
- The new currentPlayer
.
-
notifyGameFinished
Notifies all registered observers that the game has finished.- Specified by:
notifyGameFinished
in interfaceBoardGameSubject
- Parameters:
winner
- ThePlayer
who won the game.
-