#include <iostream>
usingnamespace std;
class CCharacter {
public:
CCharacter (int h, int aL, int dL) : health (h), attackLevel (aL), defenceLevel (dL) {
}
CCharacter () : health (100), attackLevel (1), defenceLevel (1) {
}
~CCharacter () {
}
int getHealth () const { return health; }
int getAttackLevel () const { return attackLevel; }
int getDefenceLevel () const { return defenceLevel; }
void increaseHealth (unsignedint iH) { health += iH; }
void decreaseHealth (unsignedint dH) { health -= dH; }
void setAttackLevel (int aL) { attackLevel = aL; }
void setDefenceLevel (int dL) { defenceLevel = dL; }
virtualvoid attack (CCharacter &target) = 0;
private:
int health;
int attackLevel;
int defenceLevel;
string name;
};
class CPlayer : public CCharacter {
public:
CPlayer () : CCharacter (100, 1, 1) { }
void attack (CCharacter &target) {
cout << "You attack the monster with " << getAttackLevel() << " attack!" << endl;
target.decreaseHealth (getAttackLevel());
cout << "The monster got hit by a " << getAttackLevel() << ", his health is now at : " << target.getHealth() << endl;
}
};
class CNPC : public CCharacter {
public:
CNPC () : CCharacter (100, 1, 1) { }
void attack (CCharacter &target) {
cout << "The monster attacks you with " << getAttackLevel() << " attack!" << endl;
target.decreaseHealth (getAttackLevel());
cout << "You got hit by a " << getAttackLevel() << ", your health is now at : " << target.getHealth() << endl;
}
};
int main ()
{
CPlayer player;
CNPC npc;
player.attack (npc);
return 0;
}
Well thanks for helping me with all of this, once I'm comfortable with c++ i'm going to be moving on to a graphics/input library, probably SDL first not sure which to start with but i'll see but again thank you so much Athar :D