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
|
//Characters.cpp
Characters::Characters() : level(0), hp(0), attack(0), defense(0) {}
//
//Characters::Characters(int seed)
//{
// // NB. your code still doesn't initialize hp, strength etc.
// // it also logs level before initializing it, so that will be garbage
//}
//Characters::Characters(int hit, int lvl, int att, int def)
// : level(lvl), hp(hit), attack(att), defense(def){}
Hero::Hero(int newHp, int newLevel, int newAttack, int newDef)
: Characters(newHp, newLevel, newAttack, newDef)
{
cout << "Hero created using Overloaded function!\n";
HeroHp = newHp;
cout << "Hp is: "<< HeroHp << endl;
Herolevel = newLevel;
cout << "level is: " << Herolevel << endl;
HeroAttack = newAttack;
cout << "Attack is: " << HeroAttack << endl;
HeroDefense = newDef;
cout << "Defense is: " << HeroDefense << endl;
// logging goes here
// note that you don't need HeroLevel etc. at all any more, just use level
}
Monsters::Monsters(int newHp, int newLevel, int newAttack, int newDef)
: MonsterHp(newHp), Monsterlevel(newLevel), MonsterAttack(newAttack)
, MonsterDefense(newDef)//initialize list
{
cout << "Monster created using Overloaded function!\n";
MonsterHp = newHp;
cout << "Hp is: "<< MonsterHp << endl;
Monsterlevel = newLevel;
cout << "level is: " << Monsterlevel << endl;
MonsterAttack = newAttack;
cout << "Attack is: " << MonsterAttack << endl;
MonsterDefense = newDef;
cout << "Defense is: " << MonsterDefense << endl;
}
Characters::~Characters()
{
cout << "Character has been destroyed!\n";
}
void Characters::setAttack(int att)
{
attack = att;
}
void Characters::setDefense(int def)
{
defense = def;
}
void Characters::setHp(int health)
{
hp = health;
}
void Characters::damageTaken(int damage)
{
hp -= damage;
}
void Characters::setlevel(int lvl)
{
level = lvl;
}
|