Package com.csse3200.game.areas
Class LevelGameGrid
java.lang.Object
com.csse3200.game.areas.LevelGameGrid
Class that stores an array of tile entities.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a tile to a given index.void
clearOccupant
(int row, int col) Clears a grid tile without a check from tile x, yvoid
clearOccupantIndex
(int index) Clears a grid tile without a check from tile x, yint
getCols()
Getter for colsgetOccupant
(int row, int col) getOccupantIndex
(int index) int
getRows()
Getter for rowsgetTile
(int index) Getter method for retrieving the tile entity instance at a given index.getTile
(int row, int col) Getter method for retrieving the tile entity instance at a given (row, col).getTileFromXY
(float x, float y) boolean
isOccupied
(int row, int col) boolean
isOccupiedIndex
(int index) boolean
placeOccupant
(int row, int col, Entity unit) Place a unit if the tile is empty from its x, y grid positionboolean
placeOccupantIndex
(int index, Entity unit) Place a unit if the tile is empty from array indexboolean
removeOccupantIfMatch
(int row, int col, Entity unit) Removes an occupant from the grid if it exists This is now Null pointer safeboolean
removeOccupantIfMatchIndex
(int index, Entity unit) Removes an occupant from the grid if it exists This is now Null pointer safevoid
Sets a specified (row, col) position on the grid to a provided tile entity.
-
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
-
getOccupantIndex
-
placeOccupant
Place a unit if the tile is empty from its x, y grid position- Parameters:
row
- the row for placementcol
- the col for placementunit
- the unit to place- Returns:
- true if successful otherwise false
-
placeOccupantIndex
Place a unit if the tile is empty from array index- Parameters:
index
- the spot in arrayunit
- the unit to place- Returns:
- true if successful otherwise false
-
removeOccupantIfMatch
Removes an occupant from the grid if it exists This is now Null pointer safe- Parameters:
row
- the row for removalcol
- the col for removalunit
- the unit to remove- Returns:
- true if successful, otherwise false
-
removeOccupantIfMatchIndex
Removes an occupant from the grid if it exists This is now Null pointer safe- Parameters:
index
- the array position of the tileunit
- 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 removalcol
- 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
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
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 interestcol
- 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
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
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
-