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.
6/26/2017 1:45:25 PM
Marko Majstorovic11 Answers
New AnswerInherit 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! :)
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.
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.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message