So I have a Class called Character which represents all the player, his companions, and all enemies. This class does a lot of things including performing actions upon other characters, and upon the environment, and so on.
I'm about to start work on a battle system for this RPG, and there will be the player controlled (and enemy controlled) units which will have a location on the screen, and a delay since their last action, and a ton of other properties and methods that apply entirely to the battle. But, this thing will also be associated in a one-to-one relationship with a Character which exists separate from a battle. It will need to access that characters stats for it's battle actions as well as some of it's methods.
So the root of my question is, is it better to create a new "Unit" class, which references the character it's associated with, or should I just expand upon the existing Character class with functions and properties that relate only to a battle? If it matters I'm writing this in C#.
BattleCharacter
really is completely a sub-type ofCharacter
, then subclass. Can you imagine a situation where a battlingUnit
might represent something other than aCharacter
? (Maybe you might later want aCatapultUnit
in the future which isn't aCharacter
.) \$\endgroup\$Unit mainUnit = (Unit)existingCharacter?
If Unit inherits from Character? That really would be ideal I think. \$\endgroup\$Unit
inherits fromCharacter
andexistingCharacter
is aCharacter
, thenUnit mainUnit = (Unit)existingCharacter
would fail, becauseUnit
is a subclass ofCharacter
and someCharacter
s might not beUnit
s. Did you mean the other way around (Character
subclassesUnit
)? \$\endgroup\$Unit
object. But if all I had was aCharacter
object, andUnit
inherited fromCharacter
what would be the best way of setting up aUnit
object which will have access to the data in an existingCharacter
object? \$\endgroup\$Character
s (and anything else even totally unrelated that can participate in a battle) implementIBattler
; then they'll all be fine to store in anIBattler
-type variable. \$\endgroup\$