I am designing a 2d rpg and am trying to decide how to program my armor system. I began by making an enum for armor types (.head, .shoulders, etc), and then an armor interface with functions like takeDamage(int d); that would reduce the durability of the piece of armor. However, I then began to realize that I would have to manually write a class that implements this interface for every piece of armor in the game, which feels like a waste of time. What is the best way of going about programming an armor system? Should I write an abstract class for each piece? or should I manually program a class for each piece of armor?
Think about what the differences between armor pieces are. Is it just where on the character to put it? If so, you only need a single class with an enum.
Or you can make an interface, with an abstract class implementing the common functions, and concrete classes implementing unique behaviour.
I get how from a functional perspective, but does this mean, structurally, I will be writing a class for each piece of armor that implements or is a child of the class/interface mentioned above?
I would make an interface IDamageable with the following members
public interface IDamageable
{
void TakeDamage(int damage);
int Durability { get; }
}
And rest depends on if your armour types are the same or not. If they all share the same members, make one class Armour implementing IDamageable. If the armour types will differ, make HeadArmour, ShouldesArmour etc., all implementing IDamageable. Maybe they could be derived from common abstract class ArmourBase.
I think this solution may be fitting. Just to be clear, you are suggesting, for example,
Class HeadArmor : baseArmour, IDamageable {
//CODE
}
right?
Right, but IDamageable could be probably on baseArmour and HeadArmor will inherit it implicitly.