I am working on creating a character sheet for a RPG I’m tinkering with. I figure out all the data I need the character sheet to keep, but I am not sure if the way I am doing it is most economical in the sense of speed and resources. Right now I have an enumeration with three types: NPC, MONSTER, PLAYER. Inside the enumeration I have a class that will store and handle all getting/setting for the stats and derived attributes. Are there any disadvantages to writing it this way? Does anyone have any suggestions?
TFYT ~Aedon
If you have a single class that checks a enumerated type and changes behavior based on that type, your code can certainly work but it may get huge, unruly, and hard to maintain as the number of behaviors increases.
Unless there’s a reason you can’t, I’d suggest using inheritance. Perhaps a base class of
Actorfrom whichNPC,Monster, andPlayerextend. Behaviors can fit neatly inside each class making reading and updating the code much cleaner.