我製作了一個簡單的基於文本的格鬥遊戲,並且我有很多麻煩讓我的子類工作。不能讓子類正常工作
了許多錯誤的即時得到最持續性是「行定義我們的‘小矮人’不符的任何聲明,‘矮人’
#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();
};
這是不同的比賽之一sublcasses,有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 ;
};
我使用的是球員類的人打,將使用「戳」
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;
};
任何幫助將不勝感激!
您還沒有指定什麼錯誤。你能告訴我們這個代碼的行爲與你的期望有什麼不同嗎? –
即時通訊錯誤消息「我們的行定義」矮人「不符合」矮人「的任何聲明 – thesowismine