Package edu.ntnu.idi.idatt.factory.board
Class LudoBoardFactory
java.lang.Object
edu.ntnu.idi.idatt.factory.board.LudoBoardFactory
- All Implemented Interfaces:
BoardFactory
LudoBoardFactory.
This class implements the BoardFactory
interface to create Ludo game boards.
It provides methods to create Ludo boards based on predefined variants (e.g., "Classic",
"Small", "Large"), from an external file, or as a blank board of a specified size.
Board variants are typically loaded from JSON files, and file handling for creating
boards from external files is delegated to LudoBoardFileHandlerGson
.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateBlankBoard
(int rows, int columns) Creates a blankLudoGameBoard
object with the given size and default player colors.createBoard
(String variant) Creates aLudoGameBoard
object based on predefined variants stored as json files in the "resources/boards" directory.createBoardFromFile
(String filePath) Creates aLudoGameBoard
object from an external file.
-
Constructor Details
-
LudoBoardFactory
public LudoBoardFactory()Constructs a newLudoBoardFactory
.
-
-
Method Details
-
createBoard
Creates aLudoGameBoard
object based on predefined variants stored as json files in the "resources/boards" directory.- Specified by:
createBoard
in interfaceBoardFactory
- Parameters:
variant
- A string specifying which board variant to create. Supported variants are "Classic", "Small", and "Large".- Returns:
- A configured
LudoGameBoard
object corresponding to the specified variant. - Throws:
IllegalArgumentException
- if the specified variant is not recognized.
-
createBoardFromFile
Creates aLudoGameBoard
object from an external file. File handling is delegated to theLudoBoardFileHandlerGson
class.- Specified by:
createBoardFromFile
in interfaceBoardFactory
- Parameters:
filePath
- The path to the file containing the board data.- Returns:
- A configured
LudoGameBoard
object, ornull
if an IOException occurs during file reading. - See Also:
-
createBlankBoard
Creates a blankLudoGameBoard
object with the given size and default player colors.- Specified by:
createBlankBoard
in interfaceBoardFactory
- Parameters:
rows
- The number of rows for the board (determines board size).columns
- The number of columns for the board (typically same as rows for Ludo).- Returns:
- A newly configured, blank
LudoGameBoard
object.
-