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.

26th Jun 2017, 1:45 PM
Marko Majstorovic
Marko Majstorovic - avatar
11 Antworten
+ 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! :)
26th Jun 2017, 7:25 PM
Zeke Williams
Zeke Williams - avatar
+ 2
Add me on Kik
23rd Jul 2017, 3:13 PM
Marko Majstorovic
Marko Majstorovic - avatar
+ 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.
26th Jun 2017, 2:17 PM
soman
+ 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.
26th Jun 2017, 2:38 PM
Jakub Stasiak
Jakub Stasiak - avatar
+ 1
Viber or name an app
23rd Jul 2017, 3:08 PM
Marko Majstorovic
Marko Majstorovic - avatar
+ 1
MarkoMajstorovic
23rd Jul 2017, 3:13 PM
Marko Majstorovic
Marko Majstorovic - avatar
0
marko i want to talk to you?
23rd Jul 2017, 3:05 PM
shubham dangi
shubham dangi - avatar
0
kik?
23rd Jul 2017, 3:09 PM
shubham dangi
shubham dangi - avatar
0
facebook instagram??
23rd Jul 2017, 3:09 PM
shubham dangi
shubham dangi - avatar
0
username?
23rd Jul 2017, 3:13 PM
shubham dangi
shubham dangi - avatar
0
i messaged u on kik
23rd Jul 2017, 3:21 PM
shubham dangi
shubham dangi - avatar