#include "my_head.hpp"
using namespace std;
class Blade;
class Sword;
class Axe;
class Hero;
class Weapon {
public:
virtual ~Weapon() = default;
virtual void applywe(Hero& hero) = 0;
};
class Hero
{
int atk;
int def;
int spd;
int hp;
public:
Hero(int _atk,int _def,int _spd,int _hp)
:atk(_atk),def(_def),spd(_spd),hp(_hp)
{
cout<<"hero的初始atk="<<atk<<endl<<"hero的初始def="<<def<<endl<<"hero的初始spd="<<spd<<endl<<"hero的初始hp="<<hp<<endl;
}
int getatk() const { return atk; }
void setatk(int value){atk=value;}
int getdef() const { return def; }
void setdef(int value){def=value;}
int getspd() const { return spd; }
void setspd(int value){spd=value;}
int gethp() const { return hp; }
void sethp(int value){hp=value;}
void equipWeapon(Weapon& weapon)
{
weapon.applywe(*this);
}
void show()
{
cout<<"hero的atk="<<atk<<endl<<"hero的def="<<def<<endl<<"hero的spd="<<spd<<endl<<"hero的hp="<<hp<<endl;
}
};
class Blade:public Weapon{
public:
void applywe(Hero& hero) const {
hero.setatk(hero.getatk()+1);
hero.setspd(hero.getspd()+1);
}
};
class Axe:public Weapon{
public:
void applywe(Hero& hero){
hero.setatk(hero.getatk()+1);
hero.sethp(hero.gethp()+1);
}
};
class Sword:public Weapon{
public:
void applywe(Hero& hero){
hero.setatk(hero.getatk()+1);
hero.setdef(hero.getdef()+1);
}
};
int main(){
Hero hero(0,0,0,0);
auto a=Sword();
hero.equipWeapon(a);
hero.equipWeapon(a);
hero.show();
}