I'm making a grid/tile based game. Each tile on the grid has a few attributes a x position, y position, and an ID. The ID changes based on what occupies the tile. Currently, there are two different types of buildings that can occupy a tile, a command center, or a turret. If I wanted to delete a building, I would need to remove it from it's ArrayList:
ArrayList<CommandCenter> commandCenters = new ArrayList<>();
ArrayList<Turret> turrets = new ArrayList<>();
Structure IDs:
Command Center : 1
Turret : 2
...
How can I pick which ArrayList to remove from, given the ID? For example(some pseudocode):
if (square(x, y).id == 1)commandCenters.remove(index);
if (square(x, y).id == 2)turrets.remove(index);
...
Is there a way to make this less tedious, or more efficient?
CommandCenter's andTurrets's descendant from a parent building class? If so you could just give each tile a property ofbuildingand choose that way.