Class LudoGameBoard

java.lang.Object
edu.ntnu.idi.idatt.model.board.BaseBoard
edu.ntnu.idi.idatt.model.board.LudoGameBoard
All Implemented Interfaces:
Board

public class LudoGameBoard extends BaseBoard
LudoGameBoard.

This class extends BaseBoard to represent the specific structure and properties of a Ludo game board. It is responsible for creating and organizing the LudoTiles that form the Ludo tracks, start areas, and finish areas for up to four players.

Key features and properties defined by this class include:

  • boardSize: An integer (typically odd, e.g., 9, 11, ..., 21) that determines the overall dimensions of the board and the length of player tracks and home areas.
  • Player colors: An array of Color objects for the four players.
  • Indexes for critical tile locations for each player:
    • playerStartIndexes: The starting tile ID for each player's tokens in their home area.
    • playerTrackStartIndexes: The tile ID where each player enters the main track .
    • playerFinishStartIndexes: The tile ID where each player enters their finish track.
    • playerFinishIndexes: The final tile ID for each player in their home stretch .
  • Sizes of specific areas: startAreaSize (dimensions of the square start area) and totalTrackTileCount (total number of tiles on the main circular track).
  • Detailed tile creation logic (createTiles(int, int)) that procedurally generates all LudoTile instances with appropriate types ("start-N", "track", "track-start-N", "finish-blank") and nextTileId connections based on the boardSize. This involves complex calculations and rotations to form the characteristic cross shape of a Ludo board.
See Also:
  • Field Details

    • boardSize

      protected int boardSize
  • Constructor Details

    • LudoGameBoard

      public LudoGameBoard(String name, String description, String background, int boardSize, javafx.scene.paint.Color[] colors)
      Constructs a new LudoGameBoard.
      Parameters:
      name - The name of the Ludo board.
      description - A description of the Ludo board.
      background - The path to the background image for the board.
      boardSize - The size of the board (e.g., 15), which dictates the track lengths. Must be an odd integer between 9 and 21, inclusive.
      colors - An array of Color objects representing the four player colors. Must not be null and must contain exactly 4 non-null colors.
  • Method Details

    • getColors

      public javafx.scene.paint.Color[] getColors()
      Returns the array of Colors assigned to the players on this Ludo board.
      Returns:
      The array of player colors.
    • getBoardSize

      public int getBoardSize()
      Returns the size of the Ludo board. This integer typically defines the length of one side of the square playing area or a similar characteristic dimension.
      Returns:
      The board size.
    • getPlayerStartIndexes

      public int[] getPlayerStartIndexes()
      Returns an array containing the starting tile IDs for each of the four players' token areas. Index 0 corresponds to player 1, index 1 to player 2, and so on.
      Returns:
      Array of player start tile IDs.
    • getPlayerTrackStartIndexes

      public int[] getPlayerTrackStartIndexes()
      Returns an array containing the tile IDs where each of the four players' main tracks begin (i.e., where tokens enter the shared playing path from their start areas). Index 0 corresponds to player 1, index 1 to player 2, and so on.
      Returns:
      Array of player track start tile IDs.
    • getPlayerFinishStartIndexes

      public int[] getPlayerFinishStartIndexes()
      Returns an array containing the tile IDs where each of the four players' finish tracks (home stretches) begin. Index 0 corresponds to player 1, index 1 to player 2, and so on.
      Returns:
      Array of player finish track start tile IDs.
    • getPlayerFinishIndexes

      public int[] getPlayerFinishIndexes()
      Returns an array containing the final (goal) tile IDs for each of the four players' finish tracks. Index 0 corresponds to player 1, index 1 to player 2, and so on.
      Returns:
      Array of player finish (goal) tile IDs.
    • getStartAreaSize

      public int getStartAreaSize()
      Returns the size (width/height) of one player's square start area. This is derived from the main boardSize.
      Returns:
      The size of the start area (e.g., if boardSize is 15, startAreaSize might be 6).
    • getTotalTrackTileCount

      public int getTotalTrackTileCount()
      Returns the total number of tiles that make up the main shared playing track (the circular path excluding individual finish tracks and start areas).
      Returns:
      The total count of tiles on the main track.
    • setColors

      public void setColors(javafx.scene.paint.Color[] colors)
      Sets the player colors for this Ludo board. Input is validated to ensure it is not null and contains exactly four non-null colors.
      Parameters:
      colors - An array of four Color objects.
      Throws:
      IllegalArgumentException - if the colors array is invalid.
    • setPlayerStartIndexes

      public void setPlayerStartIndexes(int[] playerStartIndexes)
      Sets the player start indexes for this Ludo board.
      Parameters:
      playerStartIndexes - An array of player start tile IDs.
    • setPlayerTrackStartIndexes

      public void setPlayerTrackStartIndexes(int[] playerTrackStartIndexes)
      Sets the player track start indexes for this Ludo board.
      Parameters:
      playerTrackStartIndexes - An array of player track start tile IDs.
    • setPlayerFinishStartIndexes

      public void setPlayerFinishStartIndexes(int[] playerFinishStartIndexes)
      Sets the player finish start indexes for this Ludo board.
      Parameters:
      playerFinishStartIndexes - An array of player finish track start tile IDs.
    • setPlayerFinishIndexes

      public void setPlayerFinishIndexes(int[] playerFinishIndexes)
      Sets the player finish indexes for this Ludo board.
      Parameters:
      playerFinishIndexes - An array of player finish (goal) tile IDs.
    • setStartAreaSize

      public void setStartAreaSize(int startAreaSize)
      Sets the start area size for this Ludo board.
      Parameters:
      startAreaSize - The size of the start area.
    • setTotalTrackTileCount

      public void setTotalTrackTileCount(int totalTrackTileCount)
      Sets the total track tile count for this Ludo board.
      Parameters:
      totalTrackTileCount - The total count of tiles on the main track.
    • setBoardSize

      public void setBoardSize(int boardSize)
      Sets the size of the Ludo board. This also triggers the createTiles(int, int) method to regenerate the board structure based on the new size. Input is validated to ensure it's an odd integer between 9 and 21.
      Parameters:
      boardSize - The new board size (e.g., 15).
      Throws:
      IllegalArgumentException - if the board size is invalid.
    • createTiles

      public void createTiles(int rows, int columns)
      Creates all the LudoTile instances for the Ludo board based on the current boardSize. This method is responsible for calculating the coordinates, tile IDs, next tile IDs, and types for all tiles, including start areas, the main track, and finish tracks for four players. The process involves:
      1. Calculating key dimensions like startAreaSize, tilesPerStartArea, etc.
      2. Determining start indexes for various sections (player start areas, finish tracks, main track sections).
      3. Calling helper methods createFinishSection(int) and createTrackSection(int, int, int[], int, int) to generate conceptual tile lists for these parts.
      4. Iterating through a grid representing the board and placing tiles from the generated sections into their correct (row, column) positions, instantiating them as LudoTile objects with appropriate types.
      The method ensures that the rows and columns arguments match the current boardSize.
      Parameters:
      rows - The number of rows for the board, must match boardSize.
      columns - The number of columns for the board, must match boardSize.
      Throws:
      IllegalArgumentException - if rows or columns do not match boardSize.