Add an integer data member to the Player class that keeps track of the player’s amount of gold. After
each battle, generate a random gold reward that the player receives, in addition to the experience point
award. It would make sense for harder enemies (ogres, Orc lords) to provide a larger gold reward then
orcs and goblins. Be sure to also modify the Player::viewStats() method to display the current
amount of gold the player owns.
This is my current code:
#include
#include
using namespace std;
const int max_magic_points = 100;
//max mgp = 100
class Spell
{
public:
int castSpell()
{
cout << "Cast Spells are: " << endl;
cout << "0 magic missile" << endl;
cout << "1 fireball" << endl;
cout << "2 shield" << endl;
cout << "Enter a option which is on the screen..." << endl;
int op;
cin >> op;
return op;
}
};
class Player :public Spell
{
public:
int magicPoint;
int mDamageRange;
int mMagicPointsRequired;
string mName;
Player(string name, int mgpreq, int dmr, int mgp)
{
mName = name;
mMagicPointsRequired = mgpreq;
mDamageRange = dmr;
magicPoint = mgp;
}
void hit()
{
if (magicPoint < max_magic_points)
magicPoint = magicPoint + 5;
cout << "wizard gained hit points!" << endl;
}
void characterLevelUp()
{
if (magicPoint < max_magic_points)
magicPoint++;
}
void viewStats()
{
cout << "magic points: " << magicPoint << endl;
}
void addCastSpell()
{
vector temp = { "magic missile", "fireball" , "shield" };
Spell t;
if (magicPoint >= mMagicPointsRequired)
{
string h = temp[t.castSpell()];
cout << "The cast spell is: " << h << endl;
magicPoint--;
cout << "required magic points: " << magicPoint << endl;
}
else
{
cout << " No required magic points.. " << endl;
}
}
};
//main boot
int main()
{
Player p("Player1", 10, 10, 10);
p.addCastSpell();
p.characterLevelUp();
p.hit();
p.viewStats();
return 0;
}