github存储库:https://github.com/d-parkinson/C-practice-file.git
创建于2016年4月4日,作者Darren Parkinson。这是一款由两个角色组成的双人模拟格斗游戏:恶棍与英雄每个字符分别具有四个功能:名称(字符串)、运行状况(整数)、踢球(整数)和打孔(整数)
#include <iostream>
#include <string>
包含有关字符特征的详细信息的超类
class Character{
public:
std::string name;
static int health;
int kick;
int punch;
Character(std::string name, int health, int kick, int punch){
this -> health = health;
this -> name = name;
this -> kick = kick;
this -> punch = punch;
}
~Character(){}
};
显示英雄特征的子类
class Hero : public Character{
public:
Hero(std::string name, int health, int kick, int punch) : Character(name, health, kick, punch){
std::cout << name << ": Joker giving trouble again" << std::endl;
}
~Hero(){}
};
显示绒毛特征的子类
class Villian : public Character{
public:
Villian(std::string name, int health, int kick, int punch) : Character(name, health, kick, punch){
std::cout << name << ": Hey there hehehe" << std::endl;
}
~Villian(){}
};
说明反派和英雄类之间动作的功能
void VillianPunch(Hero *hero, Villian *villian){
hero -> health -= villian -> punch;
std::cout << villian -> name << ": take this(punch)" << std::endl;
}
void VillianKick(Hero *hero, Villian *villian){
hero -> health -= villian -> kick;
std::cout << villian -> name << ": take this(kick)" << std::endl;
}
void HeroPunch(Hero *hero, Villian *villian){
villian -> health -= hero -> punch;
std::cout << hero -> name << ": take this(punch)" << std::endl;
}
void HeroKick(Hero *hero, Villian *villian){
villian -> health -= hero -> kick;
std::cout << hero -> name << ": take this(kick)" << std::endl;
}
主要功能
int main(void){
Hero *batman;
Villian *joker;
joker = new Villian("Joker",1000,90,63);
batman = new Hero("Batman",1100,93,60);
std::cout << "Fight!!!" << std::endl;
做功能模拟维廉和英雄之间的战斗
do{
HeroPunch(batman, joker);
VillianPunch(batman, joker);
VillianKick(batman, joker);
HeroKick(batman, joker);
if(batman -> health <= 0)
std::cout << joker -> name << ": You won't catch me today hehehe" << std::endl;
else if(joker -> health <= 0)
std::cout << batman -> name << ": How many times do I have to defeat you" << std::endl;
}while((batman -> health > 0) & (joker -> health > 0));
delete joker;
delete batman;
return 0;
}
我是一名新的c++程序员,正在练习git和堆栈溢出
以下错误消息:"字符::健康",引用自:
VillianPunch(英雄*,Villian*)在游戏模拟。o
游戏模拟中的VillianKick(英雄*,Villian*)。o
HeroPunch(英雄*,维廉*)在游戏模拟。o
HeroKick(英雄*,维廉*)在游戏模拟。o
_主要在游戏模拟。o
字符::字符(std::__1::basic_string,std::___1::allocater>,int,int,int)。old:
找不到体系结构x86_64 的符号
clang:错误:链接器命令失败,退出代码为1(使用-v参见调用)
代码编译了;错误消息来自链接器。(至于链接器为什么找不到它抱怨的符号,这可能是代码、游戏模拟库和标准库之间的交互中的某个地方,我不会猜测。)