Class MazeService

java.lang.Object
com.edu.xmum.CST210.Service.MazeService
All Implemented Interfaces:
IMazeService

public class MazeService extends Object implements IMazeService
Implementation of the IMazeService interface. Provides methods to handle maze-related logic.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for MazeService.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the current maze model instance.
    List<int[]>
    getPath(int x, int y)
    Provides a hint for the maze path using the DFS algorithm.
    boolean
    Checks if the player has reached the goal position in the maze.
    boolean
    isPath(int x, int y)
    Checks if the specified coordinates (x, y) are a path and not a wall.
    boolean
    isValidMove(IPlayerModel player, int dx, int dy)
    Checks if the player's move to the specified direction (dx, dy) is valid within the maze.
    boolean
    isWithinBounds(int x, int y)
    Checks if the specified coordinates (x, y) are within the maze boundaries.
    void
    Resets the maze to its initial state by generating a new maze.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MazeService

      public MazeService(IMazeModel mazeModel)
      Constructor for MazeService. Uses dependency injection to initialize the maze model.
      Parameters:
      mazeModel - The maze model instance.
  • Method Details

    • getPath

      public List<int[]> getPath(int x, int y)
      Provides a hint for the maze path using the DFS algorithm.
      Specified by:
      getPath in interface IMazeService
      Parameters:
      x - The starting x coordinate.
      y - The starting y coordinate.
      Returns:
      A list of coordinate pairs representing the path to the goal.
    • isValidMove

      public boolean isValidMove(IPlayerModel player, int dx, int dy)
      Checks if the player's move to the specified direction (dx, dy) is valid within the maze.
      Specified by:
      isValidMove in interface IMazeService
      Parameters:
      player - The player model instance.
      dx - The delta x value for the move.
      dy - The delta y value for the move.
      Returns:
      True if the move is valid, false otherwise.
    • isPath

      public boolean isPath(int x, int y)
      Checks if the specified coordinates (x, y) are a path and not a wall.
      Specified by:
      isPath in interface IMazeService
      Parameters:
      x - The x coordinate to check.
      y - The y coordinate to check.
      Returns:
      True if the coordinates represent a path, false otherwise.
    • isWithinBounds

      public boolean isWithinBounds(int x, int y)
      Checks if the specified coordinates (x, y) are within the maze boundaries.
      Specified by:
      isWithinBounds in interface IMazeService
      Parameters:
      x - The x coordinate to check.
      y - The y coordinate to check.
      Returns:
      True if the coordinates are within bounds, false otherwise.
    • hasReachedGoal

      public boolean hasReachedGoal(IPlayerModel player)
      Checks if the player has reached the goal position in the maze.
      Specified by:
      hasReachedGoal in interface IMazeService
      Parameters:
      player - The player model instance.
      Returns:
      True if the player has reached the goal, false otherwise.
    • reset

      public void reset()
      Resets the maze to its initial state by generating a new maze.
      Specified by:
      reset in interface IMazeService
    • getMaze

      public IMazeModel getMaze()
      Gets the current maze model instance.
      Specified by:
      getMaze in interface IMazeService
      Returns:
      The maze model instance.