为了学习和娱乐,我决定使用类创建一个迷你版的星际争霸 2。我创建了一个 ProtossUnit 基类和两个派生类 Zealot 和 Stalker。现在我正试图找出实施攻击的最佳方法(损坏另一个单位)。
我在 ProtossUnit 基类中包含了一个函数,但也许有更优雅/更好的方法,例如创建一个 Class Attack。我相信这将允许我对攻击进行更多的自定义(包括升级/攻击率等)。我正在考虑将 Attack 类的继承权赋予派生类,因为它们拥有伤害统计信息?
任何帮助表示赞赏。
class ProtossUnit {
protected:
int psishield, health, armor;
int mineralcost, gascost;
public:
int getHealth() { return health; }
int getPsiShield() { return psishield; }
int getArmor() { return armor; }
};
class Zealot : public ProtossUnit {
public:
string attacktype;
int damage, attackspeed;
Zealot() {
attacktype = "Psi Blades";
psishield = 50;
health = 100;
damage = 8 * 2;
attackspeed = 1.2;
mineralcost = 100;
gascost = 0;
}
};
class Stalker : public ProtossUnit {
public:
string attacktype;
int damage, attackspeed;
Stalker() {
attacktype = "Ranged";
psishield = 80;
health = 80;
damage = 10;
attackspeed = 1.44;
mineralcost = 125;
gascost = 50;
}
};
class Attack {
private:
string attackName;
int damage, attackspeed;
public:
Attack(string aName, int dmg, int aspeed) {
attackName = aName;
damage = dmg;
attackspeed = aspeed;
}
};