Advice for use of classes in rpg

Hi,
I'm trying to build a console text based rpg as a learning experience, and need some advice on designing classes.

What I had in mind is having a basic character class for describing all "actors" in the game, like the player, as well as monsters and other npc's.

The character has attributes that are used to determine the success of all actions. The character should also have a set of skills, which all have a governing attribute and improves the rate of success on corresponding actions. For example melee(physical) for fighting, persuasion(social) for npc dialouges, investigation(mental) for finding hidden things.

Now, I'm not really sure how to design the classes. For example, I want to be able to create a character object, and then assign skills to it that it can use. Right now I'm thinking I'll create a Skill class, and then store it as a vector in a Character.

1
2
3
4
5
6
7
8
9
10
11
class Skill {
public:
    Skill();

    void action();

private:
    string skillName;
    int skillLevel;
    string attribute;  //governing attribute
}


1
2
3
4
5
6
7
8
9
10
class Character {

public:
    Character();
    void getInfo();

private:
    int mental, social, physical; // character attributes
    vector<Skill> skillSet;
}


My problem with this is, how to get the character to use the skills? Should I have an Action class to contain all actions? And maybe make Skill a subclass? Or should I make one class for each individual skill that contain functions for its actions? Or should actions be included as functions in character?

If I have an Action class separate from the Character, let's say a moveTo action, how would I get the Character to use it?
Games aren't easy to make, you'll run into a lot of times where you'll be brainstorming the hell out of how to do something. Looks like right now you're figuring out class design, which in games can be pretty difficult. You really should look into polymorphism if you haven't already dude, because I can already see you're going to need it with your skill class.
For example you can have a set of skills.
Skill is a front-end for your abilities: it has a description, correctly manages mana on use and so on. On use it call an action.
Action manages targeting type (self-instacast, single-target. AOE...), types of affected characters/tiles/whatever. On actual cast it will request corresponding skill to deduct mana/resource/... and on success will apply some effect(s) on all targets.
Effect is an effect. It can be simple like "50 fire damage" or complex like "each turn deal 5 fire damage and apply action on position of affected unit"
Thanks for the replies so far. Like you say I'm just trying to brainstorm a basic structure of the code here. I guess what I'm trying to figure out right now is how to get game objects to interact. If a Character object calls an Action object, how will I get the Action to recognize that it was the player trying to do something? For example like:
1
2
3
4
5
6
enum actionID {move, shoot, talk};
class Action {
public:
   Action(actionID);
...
}

1
2
3
4
5
6
class Character {
public:
    Character();
    act( Action a );
...
}

1
2
Character player;
player.act( Action(move) );

I suppose I could pass along some more variables to Action to specify who did it, but wouldn't it kind of defeat the purpose of handling them as separate objects? I also get the feeling it could esaily get messy if I want to change something later.
Topic archived. No new replies allowed.