basically you would have a CharacterBase class.
which could look like this:
Code:
class CharacterBase {
protected:
std::string name;
int health;
int experience;
int level;
std::set< Items > inventory;
};
then all stuff that "is a" character would inherit from that base:
e.g
Code:
class OrcCharacter : public CharacterBase {
protected:
// orc specific stuff e.g which clan it belongs to
std::string clan;
}
let the player chose his character and then you can e.g.
CharacterBase *p_character = new OrcCharacter("some_name", "some_clan");
note that polymorphism is used here: that means a pointer to some class is assigned to a pointer to one of its base classes.
that is useful when you create a function which deals with all characters - not just one special kind.
e.g.
Code:
void steal_item(Character *p_thief, Character *p_victim) {
Item *p_item = p_victim->get_random_item();
if(NULL != p_item) {
p_victim->remove_item(p_item);
p_thief->insert_item(p_item);
}
}
preceding function works with all objects that are derived from character.
if some functions only works with a special character you can use typeid to check for its original type:
Character *p_character = new Orc(...);
if(typeid(*p_character) == typeid(Orc)) { // this should evaluate to true here
}
"unfortunately" typeid only works if the class has at least one virtual function.
and you might need to specify a special compiler option (e.g. /GR in vc)
well there you have some stuff to start with
note that i have not included member declarations - even though they would be there in the actual code