java.lang.Object
net.regsirius06.engine.core.graphics.labyrinth.default2D.Labyrinth2D
All Implemented Interfaces:
Iterable<List<Wall>>, ILabyrinth2D

public class Labyrinth2D extends Object implements Iterable<List<Wall>>, ILabyrinth2D
Represents a 2D labyrinth consisting of walls and light sources.

This class provides functionality for generating and interacting with a labyrinth in a 2D grid. It allows the management of walls, light sources, and spawn points, as well as collision detection.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Labyrinth2D(int dimension, int quantityOfLights, long seed)
    Constructs a new Labyrinth2D with the specified dimension and number of light sources.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    checkAddress(int x, int y)
    Checks whether the specified coordinates are within the bounds of the labyrinth.
    final Wall
    get(int x, int y)
    Retrieves the wall at the specified coordinates (x, y) in the labyrinth.
    int
    Returns the dimension of the labyrinth (i.e., the width and height of the grid).
    long
    Returns the random seed used for labyrinth generation.
    @NotNull Point
    Returns the spawn point of the labyrinth.
    boolean
    isCollidingWithWall(double x, double y)
    Checks if the specified coordinates are colliding with a wall in the labyrinth.
    @NotNull Iterator<List<Wall>>
    Returns an iterator over the rows of the labyrinth.
    final void
    set(int x, int y, Wall wall)
    Sets the wall at the specified coordinates (x, y) in the labyrinth.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.regsirius06.engine.utils.ILabyrinth2D

    get, set, set

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • Labyrinth2D

      public Labyrinth2D(int dimension, int quantityOfLights, long seed)
      Constructs a new Labyrinth2D with the specified dimension and number of light sources.

      This constructor generates a labyrinth and randomly places light sources and a spawn point.

      Parameters:
      dimension - the dimension of the labyrinth (width and height of a square grid)
      quantityOfLights - the number of light sources to generate in the labyrinth
      seed - the random seed for labyrinth generation
  • Method Details

    • get

      public final Wall get(int x, int y)
      Retrieves the wall at the specified coordinates (x, y) in the labyrinth.

      The wall represents an element of the labyrinth at the given grid location.

      Specified by:
      get in interface ILabyrinth2D
      Parameters:
      x - the x-coordinate of the wall
      y - the y-coordinate of the wall
      Returns:
      the Wall at the given coordinates
    • set

      public final void set(int x, int y, Wall wall)
      Sets the wall at the specified coordinates (x, y) in the labyrinth.

      This method allows you to modify the state of a specific wall in the labyrinth.

      Specified by:
      set in interface ILabyrinth2D
      Parameters:
      x - the x-coordinate of the wall
      y - the y-coordinate of the wall
      wall - the new wall type to set
    • checkAddress

      public boolean checkAddress(int x, int y)
      Checks whether the specified coordinates are within the bounds of the labyrinth.

      This method ensures that any point being accessed lies within the valid range of the labyrinth's grid.

      Specified by:
      checkAddress in interface ILabyrinth2D
      Parameters:
      x - the x-coordinate to check
      y - the y-coordinate to check
      Returns:
      true if the coordinates are within bounds, false otherwise
    • isCollidingWithWall

      public boolean isCollidingWithWall(double x, double y)
      Checks if the specified coordinates are colliding with a wall in the labyrinth.

      This method detects if a point within the labyrinth's grid is occupied by a non-empty wall.

      Specified by:
      isCollidingWithWall in interface ILabyrinth2D
      Parameters:
      x - the x-coordinate of the point to check
      y - the y-coordinate of the point to check
      Returns:
      true if the point is colliding with a wall, false otherwise
    • getSpawnPoint

      @NotNull public @NotNull Point getSpawnPoint()
      Returns the spawn point of the labyrinth.

      The spawn point is the location where the player or character starts within the labyrinth.

      Specified by:
      getSpawnPoint in interface ILabyrinth2D
      Returns:
      the Point representing the spawn point
    • getDimension

      public int getDimension()
      Returns the dimension of the labyrinth (i.e., the width and height of the grid).

      The dimension defines the size of the labyrinth's grid, both horizontally and vertically.

      Specified by:
      getDimension in interface ILabyrinth2D
      Returns:
      the dimension of the labyrinth
    • getSeed

      public long getSeed()
      Returns the random seed used for labyrinth generation.

      This seed is used to ensure reproducibility of the labyrinth generation process.

      Returns:
      the seed used for labyrinth generation
    • iterator

      @NotNull public @NotNull Iterator<List<Wall>> iterator()
      Returns an iterator over the rows of the labyrinth.

      This iterator allows you to traverse the labyrinth row by row.

      Specified by:
      iterator in interface Iterable<List<Wall>>
      Returns:
      an iterator for the labyrinth