I was trying to come up with a structure for a simple TD game that has following elements
Tower Each Tower has a set of properties like range, damage, health etc There could be different types of Towers with different attack types. For eg Tower A can perform attackType 1 and 2 and Tower B can perform attackType 3 and 4
Creep Each Creep has a set of properties like damage, health, bountyPoints etc. There could be different types of Creeps with different abilities just like the Towers
For now I am trying to come with a good design that is scalable and well structured for the above two game elements
This is the skeleton of a Tower class that I have come up with so far. Please comment and suggest changes. Any design patterns that could make life easier
using System.Collections; using System; public enum TowerType { tA, tB, tC }; public class Tower { private TowerType type; private int damage; private int range; private int health; public Tower(TowerType type) { this.type = type; initializeVariables(); } private void initializeVariables() { if (this.type != null) { if (this.type == TowerType.tA) { this.damage = 20; this.range = 40; this.health = 50; } else if (this.type == TowerType.tB) { this.damage = 30; this.range = 50; this.health = 60; } else if (this.type == TowerType.tC) { this.damage = 60; this.range = 60; this.health = 80; } } } public int getDamage() { return this.damage; } public int getRange() { return this.range; } public int getHealth() { return this.health; } public TowerType getTowerType() { return this.type; } public string getType(int value) { return Enum.GetName(typeof(TowerType), value); } } So using enums to define various types of towers. But is this a good design? Each Tower would have different damage, range and health.
What if there are 100 different towers? So in my InitializeVariables() would have a cluster of 100 if else statements. How can I improve on this or is there a better way to implement this?