您的位置:首页 > 新闻 > 热点要闻 > 代理网关app未运行 歌华_苏州seo门户网_最厉害的搜索引擎_郑州网络seo公司

代理网关app未运行 歌华_苏州seo门户网_最厉害的搜索引擎_郑州网络seo公司

2025/5/15 1:46:02 来源:https://blog.csdn.net/qq_68945759/article/details/146964379  浏览:    关键词:代理网关app未运行 歌华_苏州seo门户网_最厉害的搜索引擎_郑州网络seo公司
代理网关app未运行 歌华_苏州seo门户网_最厉害的搜索引擎_郑州网络seo公司

#include <iostream>
using namespace std;// 武器类(基类)
class Weapon {
protected:int atk; // 攻击力public:// 构造函数Weapon(int atk = 0) : atk(atk) {}// 虚拟析构函数virtual ~Weapon() {}// set 和 get 接口void setAtk(int atk) {this->atk = atk;}int getAtk() const {return atk;}
};// 长剑类(继承自武器类)
class Sword : public Weapon {
private:int hp; // 生命public:// 构造函数Sword(int atk = 0, int hp = 0) : Weapon(atk), hp(hp) {}// set 和 get 接口void setHp(int hp) {this->hp = hp;}int getHp() const {return hp;}
};// 短剑类(继承自武器类)
class Blade : public Weapon {
private:int spd; // 速度public:// 构造函数Blade(int atk = 0, int spd = 0) : Weapon(atk), spd(spd) {}// set 和 get 接口void setSpd(int spd) {this->spd = spd;}int getSpd() const {return spd;}
};// 斧头类(继承自武器类)
class Axe : public Weapon {
private:int def; // 防御public:// 构造函数Axe(int atk = 0, int def = 0) : Weapon(atk), def(def) {}// set 和 get 接口void setDef(int def) {this->def = def;}int getDef() const {return def;}
};// 英雄类
class Hero {
private:int atk; // 攻击力int def; // 防御力int spd; // 速度int hp;  // 生命值Weapon* equippedWeapon; // 当前装备的武器public:// 构造函数Hero(int atk = 0, int def = 0, int spd = 0, int hp = 0): atk(atk), def(def), spd(spd), hp(hp), equippedWeapon(nullptr) {}// 装备武器void equipWeapon(Weapon* p) {equippedWeapon = p;// 根据不同的武器类型进行属性加成if (dynamic_cast<Sword*>(p)) {hp += static_cast<Sword*>(p)->getHp();atk += p->getAtk();} else if (dynamic_cast<Blade*>(p)) {spd += static_cast<Blade*>(p)->getSpd();atk += p->getAtk();} else if (dynamic_cast<Axe*>(p)) {def += static_cast<Axe*>(p)->getDef();atk += p->getAtk();}}// 输出当前英雄的属性void displayStats() const {cout << "Hero stats: "<< "ATK: " << atk << ", "<< "DEF: " << def << ", "<< "SPD: " << spd << ", "<< "HP: " << hp << endl;}
};int main() {// 创建英雄Hero hero(10, 5, 3, 100);// 创建武器Sword sword(5, 20);   // 长剑:攻击力5,生命加成20Blade blade(4, 10);   // 短剑:攻击力4,速度加成10Axe axe(6, 15);       // 斧头:攻击力6,防御加成15// 装备不同的武器并显示英雄状态hero.equipWeapon(&sword);hero.displayStats();  // 长剑装备后hero.equipWeapon(&blade);hero.displayStats();  // 短剑装备后hero.equipWeapon(&axe);hero.displayStats();  // 斧头装备后return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com