I’m trying to find a smart way to store and retrieve stats for a tower defence game, but am currently unsure as to which approach would be best.
Description:
The stats system should quite basic, there are 4 different towers, with up to 5 different levels each. One important requirement is that the stats should be stored in an XML file so that the game designer easily can access and balance the stats. (He knows nothing about programming)
I can see two ways of doing this:
- By creating a TowerStats class which hold values for one type of tower for one level. Something like:
publicclassTowerStats2{publicTowerType type;publicint lvl;publicint damageLow;publicint damageHigh;publicfloat range;publicfloat attackFrequency;}
Then i would load the stats from the XMl file using Linq and XDocument and load it directly into a TowerStat List. I would do this for each tower so in the end there would be 4 different List’s which would hold the different level stats for the specified tower.
- gunTowerStats[0] would hold level 1 stats of the gun tower
- rocketTowerStats[2] would be level 3 stats of the rocket tower
When a new tower is bought by the player or when a tower is upgraded, the stats would then be taken from the List so something like:
UpgradeTower(){
lvl++;
towerStats = gunTowerStats[towerLevel -1]}
- Alternativly I could hardcode all the values, and have one big class which would go something like this:
gunTowerDamageLvl1 =4;
gunTowerDamageLvl2 =8;
gunTowerDamageLvl3 =15;
rocketTowerDamageLvl1 =10;
you get the point. I know that hardcoding is never never really the way to go. But does that also count for this kind of example where all possible values are known and will not change?
Question I’m personally in favour of the first way, but I must admit that I find both ways a bit clumsy, would it be alright to do it one of these ways or is there a much smarter and more obvious way to deal with this that I’m completely unable to see?
I hope my question is understandable.