Class LevelGameGrid

java.lang.Object
com.csse3200.game.areas.LevelGameGrid

public class LevelGameGrid extends Object
Class that stores an array of tile entities.
  • Constructor Details

    • LevelGameGrid

      public LevelGameGrid(int rows, int cols)
      Class constructor for LevelGameGrid.
      Parameters:
      rows - number of rows in the level game grid.
      cols - number of columns in the level game grid.
  • Method Details

    • getCols

      public int getCols()
      Getter for cols
      Returns:
      the number of cols in the grid
    • getRows

      public int getRows()
      Getter for rows
      Returns:
      the number of cols in the grid
    • isOccupied

      public boolean isOccupied(int row, int col)
    • isOccupiedIndex

      public boolean isOccupiedIndex(int index)
    • getOccupant

      public Entity getOccupant(int row, int col)
    • getOccupantIndex

      public Entity getOccupantIndex(int index)
    • placeOccupant

      public boolean placeOccupant(int row, int col, Entity unit)
      Place a unit if the tile is empty from its x, y grid position
      Parameters:
      row - the row for placement
      col - the col for placement
      unit - the unit to place
      Returns:
      true if successful otherwise false
    • placeOccupantIndex

      public boolean placeOccupantIndex(int index, Entity unit)
      Place a unit if the tile is empty from array index
      Parameters:
      index - the spot in array
      unit - the unit to place
      Returns:
      true if successful otherwise false
    • removeOccupantIfMatch

      public boolean removeOccupantIfMatch(int row, int col, Entity unit)
      Removes an occupant from the grid if it exists This is now Null pointer safe
      Parameters:
      row - the row for removal
      col - the col for removal
      unit - the unit to remove
      Returns:
      true if successful, otherwise false
    • removeOccupantIfMatchIndex

      public boolean removeOccupantIfMatchIndex(int index, Entity unit)
      Removes an occupant from the grid if it exists This is now Null pointer safe
      Parameters:
      index - the array position of the tile
      unit - the unit to remove
      Returns:
      true if successful, otherwise false
    • clearOccupant

      public void clearOccupant(int row, int col)
      Clears a grid tile without a check from tile x, y
      Parameters:
      row - the row for removal
      col - the col for removal
    • clearOccupantIndex

      public void clearOccupantIndex(int index)
      Clears a grid tile without a check from tile x, y
      Parameters:
      index - the array position for removal
    • addTile

      public void addTile(int index, Entity tile)
      Adds a tile to a given index.
      Parameters:
      index - Index of 1 dimensional array (NOT in rows in cols).
      tile - Tile entity that is to be stored at the index.
    • getTile

      public Entity getTile(int row, int col)
      Getter method for retrieving the tile entity instance at a given (row, col).
      Parameters:
      row - the grid's row that is storing the tile of interest
      col - the grid's column that is storing the tile of interest
      Returns:
      the tile entity found at the given (row, col) position on the grid.
    • getTile

      public Entity getTile(int index)
      Getter method for retrieving the tile entity instance at a given index.
      Parameters:
      index - the tile to get from a linear index
      Returns:
      the tile
    • setTile

      public void setTile(int row, int col, Entity tile)
      Sets a specified (row, col) position on the grid to a provided tile entity. setTile differs from addTile as setTile determines the index using the row and col values.
      Parameters:
      row - the grid's row that is to be replaced with the provided tile entity.
      col - the grid's column that is to be replaced with the provided tile entity.
      tile - the tile entity that is to be placed at the (row, col) position.
    • getTileFromXY

      public Entity getTileFromXY(float x, float y)