Class Square


public class Square extends ElementTexture
Represents a square in the game, which can be a wall, a bomb, or any other future map element.
  • Constructor Details

    • Square

      public Square(String textureName)
      Constructs a new Square with the specified texture file path and texture ID.
      Parameters:
      textureName - the texture name for this square
      Throws:
      IllegalArgumentException - if the sprite file path is null or empty
    • Square

      public Square(String textureName, boolean verticalFlip, boolean horizontalFlip, boolean diagonalFlip)
      Constructs a new Square with the specified sprite file path and texture ID.
      Parameters:
      textureName - the texture name for this square
      verticalFlip - whether to flip the texture vertically
      horizontalFlip - whether to flip the texture horizontally
      diagonalFlip - whether to flip the texture diagonally
      Throws:
      IllegalArgumentException - if the sprite file path is null or empty
    • Square

      public Square(String textureName, MapElement mapElement)
      Constructs a new Square with the specified texture file path and map element.
      Parameters:
      textureName - the texture name for this square
      mapElement - the map element associated with this square
    • Square

      public Square(String textureName, MapElement mapElement, boolean verticalFlip, boolean horizontalFlip, boolean diagonalFlip)
      Constructs a new Square with the specified texture file path and map element.
      Parameters:
      textureName - the texture name for this square
      mapElement - the map element associated with this square
      verticalFlip - whether to flip the texture vertically
      horizontalFlip - whether to flip the texture horizontally
      diagonalFlip - whether to flip the texture diagonally
  • Method Details

    • hasMapElement

      public boolean hasMapElement()
      Checks if this square has an associated map element.
      Returns:
      true if there is a map element, false otherwise
    • setMapElement

      public void setMapElement(MapElement mapElement)
      Sets the map element associated with this square.
      Parameters:
      mapElement - the map element to associate with this square
    • clearMapElement

      public void clearMapElement()
      Clears the map element associated with this square. This method sets the map element to null.
    • getMapElement

      public MapElement getMapElement()
      Returns the map element associated with this square.
      Returns:
      the map element, or null if there is no associated map element
    • isWalkable

      public boolean isWalkable()
      Checks if this square is walkable. A square is considered walkable if it does not have an associated map element.
      Returns:
      false if there is a wall or a bomb, true otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object