I had a simple concept for a 2d game. Think of like a Final Fantasy / D&D setting. I was working in C# but it's more of a general single-inheritance OO issue. I'm just assuming there's a scheme where you can implement many interfaces but inherit only one class.
There are three types of entities in the game: players, villagers, and enemies. To clarify, there can be multiple players (AI) because some may join the party.
For actions: Players can do combat and dialogue. Villagers can only use dialogue. Enemies can only do combat.
For state: All entities have a position on the map. Combatants always have current health, max health, etc. Dialogue entities always have some specific greeting text, dialogue options, etc.
Player, Villager, and Enemy would be my concrete classes. It seems I want 2 interfaces: Combat and Dialogue, handling all the actions. So far so good - however, these entities share state in a way problematic for single inheritance. Based on my design, it seems I want
- an abstract Entity class with a position on the map
- abstract classes AbstractCombatant the other AbstractDialogue both inheriting from Entity. AbstractCombatant, for example, has the state for health, equipment, etc.
The problem here is that Player would want to inherit from both Combatant and Dialogue abstract classes. With single inheritance, I can't. And if I could, I would have the diamond inheritance problem from the Entity class. Even if I just had my concrete classes inherit Entity instead, that would be another multiple inheritance problem. And of course, if I totally took the Entity part out of the equation and just mapped entities to positions separately, I would still suffer from the problem with Player inheriting from two classes.
I couldn't come up with a single-inheritance design that doesn't duplicate implementation. What is the best way to set up a class/interface hierarchy for this scenario?