Adding classes for weapon and armor in adventure game
Nov 22, 2017 at 2:19am UTC
I am asked to Make a hero class and add specific inventory slots for a weapon, armor, and ring. So far I have created the classes below but I am not sure how to implement them or at least the sword into the program. I would put my whole program but it said it was too long so let me know if you need it and a way to give it to you. I almost forgot to add this but before anyone says it I asked my professor but he has yet to get back to me still so while I wait I thought I come here.
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
class Hero
{
public :
Hero( string n, int h )
{
myName = n;
hitPoints = h;
}
int GetLife()
{
return hitPoints;
}
string GetName()
{
return myName;
}
void TakeDamage(int d)
{
hitPoints = hitPoints - d;
}
private :
int hitPoints;
string myName;
// put the rest of the inventory slots here
class Item
{
public :
Item(const std::string& name, int id)
: name(name), itemID(id) { }
const string& getName(void ) const { return this ->name; }
int getID(void ) const { return this ->itemID; }
private :
string name;
int itemID;
};
class Weapon
: public Item
{
public :
Weapon(const std::string& name, int id)
: Item(name, id) { }
virtual int getDamage(void ) const = 0;
};
class Outfit
: public Item
{
public :
Outfit(const std::string& name, int id)
: Item(name, id) { }
virtual int gethit(void ) const = 0;
virtual int gethealth(void ) const = 0;
};
class SWORD
: public Weapon
{
public :
SWORD()
: Weapon("Sword" , 0/*id*/ ) { }
virtual int getDamage(void ) const { return 100; }
};
class ARMOR
: public Outfit
{
public :
ARMOR()
: Outfit("Armor" , 1/*id*/ ) { }
virtual int gethit(void ) { return 100; }
};
class RING
: public Outfit
{
public :
RING()
: Outfit("Mystical Ring" , 3/*id*/ ) { }
virtual int gethealth(void ) { return 100; }
};
};
Last edited on Nov 22, 2017 at 2:47am UTC
Topic archived. No new replies allowed.