Class LudoBoardFactory

java.lang.Object
edu.ntnu.idi.idatt.factory.board.LudoBoardFactory
All Implemented Interfaces:
BoardFactory

public class LudoBoardFactory extends Object implements 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 Details

    • LudoBoardFactory

      public LudoBoardFactory()
      Constructs a new LudoBoardFactory.
  • Method Details

    • createBoard

      public Board createBoard(String variant)
      Creates a LudoGameBoard object based on predefined variants stored as json files in the "resources/boards" directory.
      Specified by:
      createBoard in interface BoardFactory
      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

      public Board createBoardFromFile(String filePath)
      Creates a LudoGameBoard object from an external file. File handling is delegated to the LudoBoardFileHandlerGson class.
      Specified by:
      createBoardFromFile in interface BoardFactory
      Parameters:
      filePath - The path to the file containing the board data.
      Returns:
      A configured LudoGameBoard object, or null if an IOException occurs during file reading.
      See Also:
    • createBlankBoard

      public Board createBlankBoard(int rows, int columns)
      Creates a blank LudoGameBoard object with the given size and default player colors.
      Specified by:
      createBlankBoard in interface BoardFactory
      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.