How to make general monsters?

I am making a text-based RPG for class and I want to know how to make general classes for monsters. So far I've made a CMonster class and a CFurbolg class that has inheritance from CMonster. The question is, whenever I initiate the combat sequence, it only prints you are battling a Furbolg. I want to know how to make the name and data different each time. Here's my code:

CMonster:
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
class CMonster
{
    protected:
    int health, stamina, mana, damage, x, y;
    string name;
    bool dead;
    public:
    void set_values(int a, int b, int c, int d)
    {
        health=a;
        mana=b;
        stamina=c;
        damage=d;
    }

    void setx(int _x)
    {
        x = _x;
    }

    void sety(int _y)
    {
        y = _y;
    }

    void setdead(bool _dead)
    {
        dead = _dead;
    }
};


CFurbolg:
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 CFurbolg: public CMonster
{
    public:

    CFurbolg()
    {
        name = "Furbolg";
    }

    ~CFurbolg()
    {}

    int gethealth()
    {
        return health;
    }

    int getmana()
    {
        return mana;
    }

    int getstamina()
    {
        return stamina;
    }

    string getname()
    {
        return name;
    }

    bool getdead()
    {
        return dead;
    }
};


Combat:
1
2
3
4
5
6
7
void combat()
{
    CFurbolg furbolg;
    CPlayer player;
    
    cout << "You intitiate combat with a " << ?
}


You could have an array of names. Each time you create a CFurbolg object, the constructor is going to assign a random number to a variable (use srand(time(0)) to seed the generator and rand() % <number_of_names> to create a random number which would represent the element in the array of names that is going to be chosen). Use the same method for the stats. (make sure to include <ctime> and <cstdlib>) Just to give you an idea:

1
2
3
4
5
6
7
class CMonster
{
    protected:
    //...
    string name[5];
    //...
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class CFurbolg: public CMonster
{
    int name_id;
    public:
    CFurbolg()
    {
        name[0]="name0"; name[1]="name1"; name[2]="name2"; name[3]="name3"; name[4]="name4";
        srand(time(0));
        name_id = rand() % 5;
    }

   //...
    string getname()
    {
        return name[name_id];
    }

   //...
};


1
2
3
4
5
void combat()
{
    //...
    cout << "You intitiate combat with a " << furbolg.getname();
}
Last edited on
I want a sort of general combat system so that everytime it's not a furbolg. I want to use the combat system so that it will detect what monster it is, should I set an identification integer?
I want a sort of general combat system so that everytime it's not a furbolg


Why not create multiple classes, one for each monster and have the combat system choose what monster to spawn, based on the same random number generator in my previous post?

edit: Then yes, you could use an id_integer which would identify each monster and its attributes
Last edited on
I'd have to make a seperate combat system for each monster if I were to do that. My combat system prints out information from the furbolg, but I want to be able to have more monsters...
Solved it! Thanks for input
Topic archived. No new replies allowed.