如何做搞笑原创视频网站,深圳室内设计公司排行,智能自助建站系统源码,设计师培训学校排行榜模拟一个游戏场景 有一个英雄#xff1a;初始所有属性为1 atk,def,apd,hp 游戏当中有以下3种武器 长剑Sword#xff1a; 装备该武器获得 1atx#xff0c;1def 短剑Blade#xff1a; 装备该武器获得 1atk#xff0c;1spd 斧头Axe#xff1a; 装备该… 模拟一个游戏场景 有一个英雄初始所有属性为1 atk,def,apd,hp 游戏当中有以下3种武器 长剑Sword 装备该武器获得 1atx1def 短剑Blade 装备该武器获得 1atk1spd 斧头Axe 装备该武器获得 1atk1hp 要求英雄写一个函数 equipweapon 装备武器 实现效果装备不同武器英雄获得不同的属性加成
/*有一个英雄初始所有属性为1
atk,def,spd,hp
游戏当中有以下3种武器
长剑Sword装备该武器获得1atk1def
短剑Blade装备该武器获得1atk1spd
斧头Axe装备该武器获得1atk1hp*/
#include iostreamusing namespace std;
class Hero;
class Weapon
{
public:int atk;Weapon():atk(1){}virtual void update(Hero h);int get_atk1();virtual ~Weapon(){}
};class Sword:public Weapon
{int def;
public:Sword():def(1){}void update(Hero h);
};class Blade:public Weapon
{int spd;
public:Blade():spd(1){}void update(Hero h);
};class Aex:public Weapon
{int hp;
public:Aex():hp(1){}void update(Hero h);
};class Hero
{int atk;int def;int spd;int hp;public:Hero():atk(1),def(1),spd(1),hp(1){}void set_atk(int atk);void set_def(int def);void set_spd(int spd);void set_hp(int hp);int get_atk();int get_def();int get_spd();int get_hp();void updateWeapon(Weapon *w);void show();
};
void Hero::set_atk(int atk)
{this-atkatk;
}
void Hero::set_def(int def)
{this-defdef;
}
void Hero::set_spd(int spd)
{this-spdspd;
}
void Hero::set_hp(int hp)
{this-hphp;
}
int Hero::get_atk()
{return this-atk;
}
int Hero::get_def()
{return this-def;
}
int Hero::get_spd()
{return this-spd;
}
int Hero::get_hp()
{return this-hp;
}
void Weapon::update(Hero h)
{int new_atkh.get_atk()this-atk;h.set_atk(new_atk);
}void Sword::update(Hero h)
{Weapon::update(h);int new_defh.get_def()this-def;h.set_def(new_def);
}void Blade::update(Hero h)
{Weapon::update(h);int new_spdh.get_spd()this-spd;h.set_spd(new_spd);
}void Aex::update(Hero h)
{Weapon::update(h);int new_hph.get_hp()this-hp;h.set_hp(new_hp);
}
void Hero::updateWeapon(Weapon *w)
{w-update(*this);delete w;
}
void Hero::show()
{coutatkatkendl;coutdefdefendl;coutspdspdendl;couthphpendl;
}
int main()
{Hero h1,h2,h3;h1.updateWeapon(new Sword);h2.updateWeapon(new Blade);h3.updateWeapon(new Aex);h1.show();h2.show();h3.show();return 0;
}