C# Subclass Best Practice

Viewed 2377

I am currently working on a game in XNA and I'm not sure on how I should go about doing the following...

I have a base class of buildings as such

   public class BuildingsBase
   {
     private int _hp;
     public int hp
     {
        get { return _hp; }
        set { _hp= value; }
     }

     private int _woodRequired;
     public int woodRequired
     {
        get { return _woodRequired; }
        set { _woodRequired = value; }
     }
  }

I then have multiple subclasses for building types eg.

public class TownHall:BuildingsBase
{
    public int foodHeld;

    public TownHall()
    {
        foodHeld = 100;
        woodRequired = 500;
    }
}

My question is, what is the best way of setting the default values for building subclasses.

For example, the woodRequired for a townhall is set to 500 but at various places in code I need to access this value before I have an instance of townhall declared (When checking if there is enough wood to build).

I currently have a global array of default variables for each building type but im wondering if there is a better way of doing this.

if (Globals.buildingDefaults[BuildingType.Townhall].woodRequired < Globals.currentWood)
{
    Townhall newTH = new Townhall();
}
1 Answers
Related