一般在游戏中,我们会有这样的定义Player和怪物NPC:
// 基类 Character
class Character {
protected:std::string name;int64_t id;int32_t hp;int32_t mp;int32_t level;public:Character(const int64_t name) : id(id) {}virtual void attack() {std::cout << id<< " attacks!" << std::endl;//....}virtual void defend() {std::cout << id<< " defends!" << std::endl;//....}void addhp(int32_t modhp){hp += modhp;}//.....
};// 玩家类 Player
class Player : public Character {
public:Player(const int64_t id) : Character(id) {}void attack() override {std::cout << name << " attacks with a powerful sword!" << std: