Class BoardGame

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

public abstract class BoardGame extends Object implements Game, BoardGameSubject
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 Details

    • logger

      protected static final org.slf4j.Logger logger
    • observers

      protected final List<BoardGameObserver> observers
    • board

      protected Board board
    • players

      protected List<Player> players
    • currentPlayer

      protected Player currentPlayer
    • dice

      protected Dice dice
    • roundNumber

      protected int roundNumber
  • Constructor Details

    • BoardGame

      protected BoardGame(Board board, List<Player> players, int diceCount)
      Constructor for BoardGame.
      Parameters:
      board - The game board
      players - The list of players
      diceCount - 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 interface Game
    • getBoard

      public Board getBoard()
      Description copied from interface: Game
      Gets the game board.
      Specified by:
      getBoard in interface Game
      Returns:
      the game board
    • getDice

      public Dice getDice()
      Description copied from interface: Game
      Gets the game dice.
      Specified by:
      getDice in interface Game
      Returns:
      the game dice
    • getPlayers

      public List<Player> getPlayers()
      Description copied from interface: Game
      Gets all players in the game.
      Specified by:
      getPlayers in interface Game
      Returns:
      list of all players
    • getCurrentPlayer

      public Player getCurrentPlayer()
      Description copied from interface: Game
      Gets the current player.
      Specified by:
      getCurrentPlayer in interface Game
      Returns:
      the current player
    • getRoundNumber

      public int getRoundNumber()
      Description copied from interface: Game
      Gets the current round number.
      Specified by:
      getRoundNumber in interface Game
      Returns:
      the current round number
    • setBoard

      public void setBoard(Board board)
      Sets the game board.
      Specified by:
      setBoard in interface Game
      Parameters:
      board - The Board to be used for the game.
    • setPlayers

      public void setPlayers(List<Player> players)
      Sets the list of players for the game.
      Specified by:
      setPlayers in interface Game
      Parameters:
      players - A list of Player objects participating in the game.
    • setCurrentPlayer

      public void setCurrentPlayer(Player player)
      Sets the current player.
      Specified by:
      setCurrentPlayer in interface Game
      Parameters:
      player - The player to set as current
    • addObserver

      public void addObserver(BoardGameObserver observer)
      Adds an observer to be notified of game events.
      Specified by:
      addObserver in interface BoardGameSubject
      Parameters:
      observer - The BoardGameObserver to add.
    • removeObserver

      public void removeObserver(BoardGameObserver observer)
      Removes an observer from the list of observers.
      Specified by:
      removeObserver in interface BoardGameSubject
      Parameters:
      observer - The BoardGameObserver 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 interface Game
    • 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 interface BoardGameSubject
      Parameters:
      roundNumber - The new round number.
    • notifyCurrentPlayerChanged

      public void notifyCurrentPlayerChanged(Player player)
      Notifies all registered observers that the current player has changed.
      Specified by:
      notifyCurrentPlayerChanged in interface BoardGameSubject
      Parameters:
      player - The new current Player.
    • notifyGameFinished

      public void notifyGameFinished(Player winner)
      Notifies all registered observers that the game has finished.
      Specified by:
      notifyGameFinished in interface BoardGameSubject
      Parameters:
      winner - The Player who won the game.