I am making this 2-D game where I want to be able to build structures. The player must be able to benefit from certain structures. Today the game looks like this:
(the blue dot is the player, other dots are ais)
I have made a class named Structure and three other classes that inherits from Structure. These classes are more or less empty. The tiles of the game has there own class named Tile. In this class I have written some things but the code of interest is this:
public LinkedList<Structure> Structures = new LinkedList<Structure>();
When i build a structure (a fireplace for example) the code looks like this:
Bundle.map.tile[Bundle.player.X, Bundle.player.Y].Structures.
AddFirst(new Fireplace());
The part I´m uncertain about is how I check if the list contain a fireplace for example (which is a class named Fireplace) or any other building. For example if a player finds a fireplace on a tile he/she will regain warmth. This does not work. Perhaps I have the wrong approach to all this, in either case please provide me with an code example.
Conclusion of answer:
bool anyFireplace = Bundle.map.tile[Bundle.player.X, Bundle.player.Y].Structures.OfType<Fireplace>().Any();
if (anyFireplace)
{
Warmth = MaxWarmth;
}
else
{
if (Warmth > 0)
{
Warmth--;
}
else
{
HP--;
}
}