What usually happens is that they create flies ( see figure ). This object contains properties that are in any case the same for each instance. There is no need to change (or actually store) the required amount of wood for each instance separately.
In a very basic design, it will look like this:
class BuildingTemplate { public int WoodRequired { get; set; } } class Templates { public static BuildingTemplate TownHall { get; set; } }
In the end, you should call a method like:
public bool CanBuildTownHall(Player player) { return player.HasEnoughResources(Templates.TownHall); }
Of course, you can use the dictionary to extract the template, and players should not be aware of the building requirements. I just illustrate the template here.
If the player has enough resources, you can use the template to subtract the amount and create the actual TownHall
instance. It is nice to have a link to the actual template, because you are likely to access other global properties that are also valid for all TownHall
(for example, audio / visual //.).//
class TownHall { public TownHall(BuildingTemplate template) { _template = template; } }
source share