Ok, this is going to be long :P
Try writing a RPG. It may sound simple but it can really push both your design and programming skills to their limit and beyond.
A first approach would be throwing some global functions and variables in your text editor, and then feed that to your compiler. Something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
//...
string player_name;
int player_level;
int player_HP;
int player_attack;
int player_defense;
//...
string monster_name;
int monster_HP;
int monster_attack;
int monster_defense;
//...
void player_attack();
void player_level_up();
//...
void monster_attack();
//...
int main()
{
//...
return 0;
};
//...
|
Then, you'll realize that you can organize this global mess in an object oriented way. Like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
//...
class Player
{
private:
//data
string name;
//...
public:
//functions
void attack(Monster & target);
//...
};
//...
|
Advanced mechanisms like inheritance and polymorphism will gradually come into play:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
class Entity
{
protected:
string name;
//...
public:
virtual void attack(Entity & target);
//...
};
class Player: public Entity
{
//...
public:
virtual void attack(Entity & target);
//...
};
class Monster: public Entity
{
//...
public:
virtual void attack(Entity & target);
//...
};
|
Eventually, you'll have to make some major design decisions. How will you implement your hero's class system? Will there be classes or will it be a skill-based system? If there are classes, will you implement them using multiple inheritance, like this:
1 2 3
|
class Wizard: virtual public Player {/*...*/};
class Fighter: virtual public Player {/*...*/};
class BattleMage: public Wizard, public Fighter {/*...*/};
|
?
Or composition, like this:
1 2 3 4 5 6 7 8 9
|
class Role {/*...*/};
class Wizard: public Role {/*...*/};
class Fighter: public Role {/*...*/};
class Player: public Entity
{
vector<Role*> role_list;
//...
};
|
?
And what about your skills/spells? Will they be leafs of a fixed inheritance tree, like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
class Spell
{
protected:
int mana_cost;
int cooldown;
//...
public:
virtual void Use(Entity & caster, Entity & target)=0;
//...
};
class OffensiveSpell: public Spell
{
int damage;
int critical_chance;
int critical_multiplier;
//...
public:
virtual void Use(Entity & caster, Entity & target);
//...
};
class DefensiveSpell: public Spell
{
int magnitude;
//...
public:
virtual void Use(Entity & caster, Entity & target);
//...
};
class Fireball: public OffensiveSpell {/*...*/};
class Heal: public DefensiveSpell {/*...*/};
//...
|
?
Or will you implement a scripting approach, and perhaps add the option for the user to create his own spells, like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
class Action
{
public:
virtual void DoIt(Entity & caster, Entity & target)=0;
};
class ModifyHP: public Action
{
int amount;
bool is_damage; //or heal?
bool target_self; //or enemy?
public:
virtual void DoIt(Entity & caster, Entity & target);
//...
};
//other basic actions derived from Action here
//...
class Spell
{
vector<Action*> action_list;
public:
void Use(Entity & caster, Entity & target)
{
for (int i=0; i<action_list.size(); i++)
action_list[i]->DoIt(Entity & caster, Entity & target);
}
//...
};
|
?
And we haven't even talked about the Item system and many other things (game map, game areas (towns, dungeons, etc...), npcs, scenario...). The possibilities are endless.
Finally, another big decision -> Will this be console-based or will you use a graphics library? Disch might tell you here to use SFML or something like that, but I'd find a better idea to write a text-based RPG with Disch trapped in the console and trying to escape :D But, in the end, the choice is up to you :P
Useful link ->
http://www-cs-students.stanford.edu/~amitp/gameprog.html