I have a List of about 100 objects which just so happen to be tiles. It looks like this:
List<Tile> Tiles;
Elsewhere in my code I have classes that derive from the tile base class, I’ll use house for this example:
public class house : Tile
Inside of the list up top I have added different types of tiles to the data structure:
Tiles.add(new house());
Tiles.add(new church()); //ect. ect.
My question is how do I know which tiles are churches or houses if I where to reference that list through a control structure like a for-loop. Basically I need to compare two tiles of different types together. Is it even possible to know which child class I am referencing? I’m sure there’s an easy explanation to this however I’m not very well versed when it comes to Object-Oriented programming so i’m not even entirely sure what i’m supposed to be looking for when it comes to help.
There are various options here
is/asto check a particular object to see if it is of a particular type.TileType(compare: Expression.NodeType)virtualmethod so that you don’t need to know what the type is: you just say “do whatever your type does here” (i.e. invoke the virtual method)