Question about class?

I am making a new class/object called monster_all for my first test RPG game. This is my first non player object I am making.

My understanding of classes is you put int and chars into private that you want to remain static; things you don't want the player to manipulate.You put methods, int, and chars into public, and these are items that the player can touch, change, and manipulate. Am I right?

Now if those above are right, then what would I put monster-all's attack named fireBreath in? Lets say the player puts a damage reducer on monster_all, he is technically manipulating the monsters damage.
All of those assumptions would be correct.
I would put the damage inside of private and have a modifier in public. ex. modifier = -50%
Your understanding (or explanation) of classes is not very good, but I guess not very bad either.

A class encapsulates private data so other objects are not "tempted" to tamper with them. Basically that's the encapsulation principle. It is good because you then are provided with specific things that you CAN do through the public interface.

What you want to do can be accomplish in several ways, but none are simple or trivial and require that you understand classes and OOP. In your particular example, the Decorator design pattern (http://en.wikipedia.org/wiki/Decorator_pattern ) sounds like one good way to go.

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
38
39
class Monster
{
protected:
    //Helper function that calculates the damage to inflict on a player:
    int AttackDamage(Player &thePlayer)
    {
        ...
    }
public:

    virtual void Attack(Player &thePlayer)
    {
        //Code to do standard damage here.  Uses AttackDamage().
        ...
    }
};

//Now the decorator class that "tampers" or modifies the way the monster can perform damage:
class MinimizeMonsterDamageSpell : public Monster
{
    //Private data:
    Monster *_theMonster;

public:
    //Construction
    MinimizeMonsterDamageSpell(Monster * const theMonster) : _theMonster(theMonster)
    { }

    //Delegate all public members to the implementation inside the monster object pointed to by _theMonster.
    //In the case of Attack() (the only public member in this sample for Monster),
    //override the functionality so the damage is less by some percentage.
    virtual void Attack(Player &thePlayer)
    {
        int damage = AttackDamage(thePlayer);
        damage *= 0.90; //10% bonus
        Now apply the reduced damage to the player object via Player's public interface.
        ...
    }
}; 


In this construction, you can "wrap" or "decorate" the original monster object with a spell (or otherwise) object that modifies the attack produced by said monster. The decorated object is also a Monster object because it inherits from it, meaning you can still use this decorated monster object where ever you need a monster. Beautiful, isn't it? :-) Hope it helps.
Topic archived. No new replies allowed.