我制作了一个简单的基于文本的格斗游戏,我在让我的子类工作时遇到了很多麻烦。
在我遇到的许多错误中,最持久的是“我们的行定义“矮人”与任何“矮人”声明都不匹配
#include <iostream>
using namespace std;
class Poke{
protected:
string race;
int health, damage, shield;
public:
Poke();
Poke(int health, int damage, int shield);
virtual int attack(Poke*);
virtual int defend(Poke*);
virtual int getHealth();
};
这是不同种族的一个子类,还有 2 个具有不同级别的攻击/健康/盾牌
// Dwarf: High health, Low attack, High defense
class Dwarf: public Poke {
public:
string race = "Dwarf";
int attack(Poke*);
int defend(Poke*);
int getHealth();
};
.cpp V
//DWARF
Dwarf::Dwarf(int health, int damage, int shield) {
this->health = 100;
this->damage = 50;
this->shield = 75;
};
//attack
int Poke:: attack(Poke*){
if (shield > (damage + rand() % 75)){
cout << "Direct Hit! you did" << (health - damage) << "points of damage";
}
else {std::cout << "MISS!"<<;
}
return 0;
};
int Poke:: attack(Poke*){
Enemy this->damage ;
};
我正在为玩将使用“Poke”的游戏的人使用玩家类
class Player{
int wins, defeats, currentHealth;
string name;
Poke race;
bool subscribed;
public:
Player(int wins, int defeats, int currentHealth);
int addWins();
int addDefeats();
int getWins();
int getDefeats();
int getHealth();
};
.cpp V
//getHealth
int Player::getHealth(){
return this->currentHealth;
};
和计算机对手的“敌人”类:
class Enemy{
int eHealth;
Poke eRace;
public:
Enemy (int eHealth, Poke eRace);
int getEHealth;
};
.cpp V
int Enemy:: getEHealth(){
return this->eHealth;
};
任何帮助将非常感激!!