Class World
- All Implemented Interfaces:
Serializable
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 worldwidth- the width of the worldheight- the height of the worlddimension- the dimensionality of the world (typically 2D or 3D)quantityOfLight- the amount of light in the worldseed- the random seed used for generating the worldkeyDefinition- the key bindings for interacting with the worldlabyrinth- 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
FieldsModifier and TypeFieldDescriptionstatic final org.slf4j.LoggerThe logger for theWorldclass, used to log messages related to world operations. -
Constructor Summary
ConstructorsConstructorDescriptionWorld(String name, int width, int height, int dimension, int quantityOfLights, long seed, KeyDefinition keyDefinition, @NotNull Initializer<? extends AbstractLabyrinthPanel> labyrinth) Constructs a newWorldwith the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the height of the world.Returns the labyrinth panel associated with this world, initialized with the world-specific settings.getName()Returns the name of this world.@NotNull StringgetPath()Returns the path to the file where this world is saved.static @NotNull StringReturns the path to the file where this world is saved, based on the world name.Returns a list of names of all saved worlds.intgetWidth()Returns the width of the world.static @Nullable WorldLoads a world from the file system using the given world name.voidsave()Saves this world to a file at the specified path.
-
Field Details
-
log
public static final org.slf4j.Logger logThe logger for theWorldclass, used to log messages related to world operations.This
Loggerinstance is responsible for logging events and errors related to the operations performed on theWorldobject, 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, andERROR. 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 newWorldwith the given parameters.- Parameters:
name- the name of the worldwidth- the width of the worldheight- the height of the worlddimension- the dimension of the world (e.g., 2D or 3D)quantityOfLights- the number of light sources in the worldseed- the random seed for generating the worldkeyDefinition- the key bindings for interacting with the worldlabyrinth- the labyrinth initializer that is used to create the labyrinth in the world
-
-
Method Details
-
getLabyrinth
Returns the labyrinth panel associated with this world, initialized with the world-specific settings.- Returns:
- an instance of the labyrinth panel
-
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
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
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
Loads a world from the file system using the given world name.- Parameters:
name- the name of the world to load- Returns:
- the loaded
Worldinstance, ornullif the world could not be loaded
-
getSavedWorlds
Returns a list of names of all saved worlds.- Returns:
- a list of saved world names
-