0
C++ class manipulation
For example: class Race has HP,DMG and Crit chance class Power has also HP,DMG and Crit chance This is similar to the WoW game so it would be easy for you to figure out. The class Race has default value for all of its members like Human,Gnome etc. The class Power gives the buffs for example +10HP -20DMG +0.4Crit chance. My question is how could i write it down in code the C++ course has some basic stuff that isn't enough.
11 Réponses
+ 2
Inherit from a base class:
class myClass {
protected:
int HP, DMG, CritChance;
public:
myClass(int hp, int dmg, int crit)
: HP(hp), DMG(dmg), CritChance(crit) {};
};
class Race: public myClass {
public:
Race(): myClass(20, 5, 45) {}
}
If this example is not enough, I could write something in the playground for you to look at. Happy Coding! :)
+ 2
Add me on Kik
+ 1
Write some class Object which has three parameters fields and accept all of them in its constructor. Then you can add another three fields - offsets. It will be the Power. And make some functions as members like
enablePower (hp, dmg, anythingElse);
and
disablePower () which just calls enablePower (0, 0, 0);
I have never played WoW, but hope it helped you.
+ 1
If I understand right:
In constructor of Race you can pass Power as an argument, and then inside constructors' body calculate default values for given Race with given Power.
+ 1
Viber or name an app
+ 1
MarkoMajstorovic
0
marko i want to talk to you?
0
kik?
0
facebook instagram??
0
username?
0
i messaged u on kik