Class LabyrinthPanel

All Implemented Interfaces:
KeyListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, UIKeyListener, Drawable2D

public class LabyrinthPanel extends AbstractLabyrinthPanel
Represents a panel for rendering a labyrinth game and handling user input. This class extends JPanel and provides a user interface to interact with the labyrinth game. It handles key events for player movement and rendering of the labyrinth graphics and a mini-map.

The panel allows users to control the player within the labyrinth using keyboard input. It also displays the labyrinth, with visual elements such as light sources and a mini-map.

See Also:
  • Constructor Details

    • LabyrinthPanel

      public LabyrinthPanel(int width, int height, int dimension, int quantityOfLights, long seed, KeyLogic keyLogic)
      Constructs a new LabyrinthPanel with the specified parameters. This constructor initializes the labyrinth, player, key logic, and graphics renderer. It also sets up the mini-map and adds the necessary key listener for player interaction.
      Parameters:
      width - The width of the panel in pixels.
      height - The height of the panel in pixels.
      dimension - The dimension of the labyrinth grid.
      quantityOfLights - The number of light sources in the labyrinth.
      seed - The seed value used for generating the labyrinth layout, ensuring reproducibility.
      keyLogic - The key logic used for player movement.
  • Method Details

    • draw

      public void draw(Graphics2D g2d)
      Paints the component, rendering the labyrinth and any additional UI elements such as the mini-map. This method is called automatically when the panel needs to be re-rendered.
      Parameters:
      g2d - The Graphics2D object used for drawing the panel's content.
    • keyPressed

      public final void keyPressed(@NotNull @NotNull KeyEvent e)
      Handles key press events to control player movement and toggle the visibility of the mini-map.

      This method delegates movement control to KeyLogic.keyMoveAnalysis(KeyEvent, Player, Labyrinth2D) and checks whether the mini-map should be toggled based on key input. If a relevant key is pressed, the mini-map visibility state is updated accordingly.

      Parameters:
      e - The KeyEvent that describes the key press event.