Package edu.ntnu.idi.idatt.model.board
Class LudoGameBoard
java.lang.Object
edu.ntnu.idi.idatt.model.board.BaseBoard
edu.ntnu.idi.idatt.model.board.LudoGameBoard
- All Implemented Interfaces:
Board
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 LudoTile
s 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) andtotalTrackTileCount
(total number of tiles on the main circular track). - Detailed tile creation logic (
createTiles(int, int)
) that procedurally generates allLudoTile
instances with appropriate types ("start-N", "track", "track-start-N", "finish-blank") andnextTileId
connections based on theboardSize
. This involves complex calculations and rotations to form the characteristic cross shape of a Ludo board.
- See Also:
-
Field Summary
FieldsFields inherited from class edu.ntnu.idi.idatt.model.board.BaseBoard
background, description, name, tiles
-
Constructor Summary
ConstructorsConstructorDescriptionLudoGameBoard
(String name, String description, String background, int boardSize, javafx.scene.paint.Color[] colors) Constructs a newLudoGameBoard
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
createTiles
(int rows, int columns) Creates all theLudoTile
instances for the Ludo board based on the currentboardSize
.int
Returns the size of the Ludo board.javafx.scene.paint.Color[]
Returns the array ofColor
s assigned to the players on this Ludo board.int[]
Returns an array containing the final (goal) tile IDs for each of the four players' finish tracks.int[]
Returns an array containing the tile IDs where each of the four players' finish tracks (home stretches) begin.int[]
Returns an array containing the starting tile IDs for each of the four players' token areas.int[]
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).int
Returns the size (width/height) of one player's square start area.int
Returns the total number of tiles that make up the main shared playing track (the circular path excluding individual finish tracks and start areas).void
setBoardSize
(int boardSize) Sets the size of the Ludo board.void
setColors
(javafx.scene.paint.Color[] colors) Sets the player colors for this Ludo board.void
setPlayerFinishIndexes
(int[] playerFinishIndexes) Sets the player finish indexes for this Ludo board.void
setPlayerFinishStartIndexes
(int[] playerFinishStartIndexes) Sets the player finish start indexes for this Ludo board.void
setPlayerStartIndexes
(int[] playerStartIndexes) Sets the player start indexes for this Ludo board.void
setPlayerTrackStartIndexes
(int[] playerTrackStartIndexes) Sets the player track start indexes for this Ludo board.void
setStartAreaSize
(int startAreaSize) Sets the start area size for this Ludo board.void
setTotalTrackTileCount
(int totalTrackTileCount) Sets the total track tile count for this Ludo board.Methods inherited from class edu.ntnu.idi.idatt.model.board.BaseBoard
addTile, getBackground, getDescription, getName, getTile, getTileCount, getTiles, setBackground, setDescription, setName
-
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 newLudoGameBoard
.- 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 ofColor
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 ofColor
s 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 mainboardSize
.- 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 fourColor
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 thecreateTiles(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 theLudoTile
instances for the Ludo board based on the currentboardSize
. 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:- Calculating key dimensions like
startAreaSize
,tilesPerStartArea
, etc. - Determining start indexes for various sections (player start areas, finish tracks, main track sections).
- Calling helper methods
createFinishSection(int)
andcreateTrackSection(int, int, int[], int, int)
to generate conceptual tile lists for these parts. - 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.
rows
andcolumns
arguments match the currentboardSize
.- Parameters:
rows
- The number of rows for the board, must matchboardSize
.columns
- The number of columns for the board, must matchboardSize
.- Throws:
IllegalArgumentException
- ifrows
orcolumns
do not matchboardSize
.
- Calculating key dimensions like
-