java.lang.Object
tech.underoaks.coldcase.state.tiles.Tile
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
EmptyTile, GroundTile

public abstract class Tile extends Object implements Cloneable
The Tile class represents a single tile on the game board. Each tile can hold a specific TileContent, which may be an item, a static object like a wall, or any other entity that occupies a tile.

This class provides rendering functionality, allowing each tile to display its texture on the screen. The texture and content of each tile can be configured and updated, enabling dynamic changes on the game board.

As an abstract class, Tile can be extended to create specific types of tiles with unique behaviors or additional properties.

See Also:
  • Constructor Details

    • Tile

      public Tile(com.badlogic.gdx.graphics.Texture texture)
      Constructs a new Tile with the specified texture.

      This constructor initializes the tile's texture and creates a corresponding Sprite, setting its origin to the center. The texture is used for rendering the tile.

      Parameters:
      texture - the Texture to be used for this tile's appearance
  • Method Details

    • render

      public void render(com.badlogic.gdx.graphics.g2d.Batch batch, float x, float y)
      Renders the tile at the specified coordinates using the given SpriteBatch. If the tile has no texture, this method renders nothing.

      If the tile has a TileContent, the render method of the content is called.

      Parameters:
      batch - the SpriteBatch used to render the tile
      x - the x-coordinate for rendering the tile
      y - the y-coordinate for rendering the tile
    • getTileContent

      public TileContent getTileContent()
      Retrieves the TileContent currently placed on this tile.
      Returns:
      the current TileContent on the tile, or null if none is set
    • setTileContent

      public void setTileContent(TileContent tileContent)
      Sets the TileContent for this tile.

      This method replaces any existing content on the tile with the specified TileContent.

      Parameters:
      tileContent - the new TileContent to set on the tile
    • pushTileContent

      public void pushTileContent(TileContent tileContent)
      Adds the specified TileContent to this tile.

      If the tile currently has no content, the provided TileContent is set directly. Otherwise, the new content is pushed onto the existing content stack.

      Parameters:
      tileContent - the TileContent to add to the tile
    • popTileContent

      public TileContent popTileContent()
      Removes and returns the top TileContent from this tile.

      If the tile's content is a stack (i.e., contains nested TileContent), this method removes and returns the top element of that stack. If there is only one content element, it is removed and the tile's content is set to null. If the tile has no content, null is returned.

      Returns:
      the removed TileContent, or null if the tile was empty
    • topTileContent

      public TileContent topTileContent()
      Retrieves the top TileContent from this tile without removing it.

      If the tile's content is a stack of TileContent objects, this method returns the top element of that stack. If the tile has no content, it returns null.

      Returns:
      the top TileContent on the tile, or null if the tile is empty
    • clone

      public Tile clone()
      Overrides:
      clone in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • dispose

      public void dispose()
      Releases the resources used by this tile.

      Disposes of the tile's texture if it is not null, and also calls dispose() on its TileContent if present.