Class World

java.lang.Object
net.regsirius06.engine.world.World
All Implemented Interfaces:
Serializable

public final class World extends Object implements Serializable
The World class represents a game world, including a labyrinth and various attributes such as the world size, lighting, and world-specific settings. It allows for the management of the world, including saving and loading worlds from files.

A world is defined by the following attributes:

  • name - the name of the world
  • width - the width of the world
  • height - the height of the world
  • dimension - the dimensionality of the world (typically 2D or 3D)
  • quantityOfLight - the amount of light in the world
  • seed - the random seed used for generating the world
  • keyDefinition - the key bindings for interacting with the world
  • labyrinth - the labyrinth that represents the core of the world

The World class also provides functionality for saving and loading the world to/from a file, and retrieving a list of all saved worlds. It provides methods to create a labyrinth with the given settings.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.slf4j.Logger
    The logger for the World class, used to log messages related to world operations.
  • Constructor Summary

    Constructors
    Constructor
    Description
    World(String name, int width, int height, int dimension, int quantityOfLights, long seed, KeyDefinition keyDefinition, @NotNull Initializer<? extends AbstractLabyrinthPanel> labyrinth)
    Constructs a new World with the given parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the height of the world.
    Returns the labyrinth panel associated with this world, initialized with the world-specific settings.
    Returns the name of this world.
    @NotNull String
    Returns the path to the file where this world is saved.
    static @NotNull String
    Returns the path to the file where this world is saved, based on the world name.
    static @NotNull List<String>
    Returns a list of names of all saved worlds.
    int
    Returns the width of the world.
    static @Nullable World
    load(@NotNull String name)
    Loads a world from the file system using the given world name.
    void
    Saves this world to a file at the specified path.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • log

      public static final org.slf4j.Logger log
      The logger for the World class, used to log messages related to world operations.

      This Logger instance is responsible for logging events and errors related to the operations performed on the World object, such as saving, loading, and other internal processes. The logger is configured using the SLF4J logging framework, which allows for flexible logging output, including console output, file logging, or integration with external logging systems.

      Example usage:

       log.info("World has been successfully loaded.");
       log.error("Failed to save the world: {}", e.getMessage());
       

      The logging level can be adjusted in the SLF4J configuration to control the verbosity of the log messages. Common log levels include DEBUG, INFO, WARN, and ERROR. By default, the log messages are output to the console, but this can be configured as needed.

  • Constructor Details

    • World

      public World(String name, int width, int height, int dimension, int quantityOfLights, long seed, KeyDefinition keyDefinition, @NotNull @NotNull Initializer<? extends AbstractLabyrinthPanel> labyrinth)
      Constructs a new World with the given parameters.
      Parameters:
      name - the name of the world
      width - the width of the world
      height - the height of the world
      dimension - the dimension of the world (e.g., 2D or 3D)
      quantityOfLights - the number of light sources in the world
      seed - the random seed for generating the world
      keyDefinition - the key bindings for interacting with the world
      labyrinth - the labyrinth initializer that is used to create the labyrinth in the world
  • Method Details

    • getLabyrinth

      public AbstractLabyrinthPanel getLabyrinth()
      Returns the labyrinth panel associated with this world, initialized with the world-specific settings.
      Returns:
      an instance of the labyrinth panel
    • getName

      public String getName()
      Returns the name of this world.
      Returns:
      the name of the world
    • getWidth

      public int getWidth()
      Returns the width of the world.
      Returns:
      the width of the world
    • getHeight

      public int getHeight()
      Returns the height of the world.
      Returns:
      the height of the world
    • getPath

      @Contract(pure=true) @NotNull public static @NotNull String getPath(String name)
      Returns the path to the file where this world is saved, based on the world name.
      Parameters:
      name - the name of the world
      Returns:
      the file path where the world is saved
    • getPath

      @Contract(pure=true) @NotNull public @NotNull String getPath()
      Returns the path to the file where this world is saved.
      Returns:
      the file path where this world is saved
    • save

      public void save()
      Saves this world to a file at the specified path.
    • load

      @Nullable public static @Nullable World load(@NotNull @NotNull String name)
      Loads a world from the file system using the given world name.
      Parameters:
      name - the name of the world to load
      Returns:
      the loaded World instance, or null if the world could not be loaded
    • getSavedWorlds

      @NotNull public static @NotNull List<String> getSavedWorlds()
      Returns a list of names of all saved worlds.
      Returns:
      a list of saved world names