【发布时间】:2016-04-06 02:58:34
【问题描述】:
我正在尝试用 C++ 制作游戏。我的编辑器是 Code::Blocks,我的编译器是 MinGW。该游戏是一个基于文本的生存游戏,变量为饥饿、口渴、温暖和选择。当我试图告诉玩家饥饿、口渴和温暖的值时,它给了我这个问题标题所陈述的错误。我是一个相对较新的程序员,但我了解基础知识。我现在将打印我使用的代码:
cout<< "Your hunger is"; hunger; endl;
cout<< "Your warmth is"; warmth; endl;
cout<< "Your thirst is"; thirst; endl;
这是变量发生变化的地方(这是一个例子):
int wood()
{
cout<< "You have chosen find firewood!"<< endl;
if ((rand() % 2) == 2){
cout<< "You found firewood!"<<endl;
warmth = warmth + 1;
}
else{
cout<< "You could not find any firewood"<< endl;
}
}
在我告诉玩家代码的同一个函数中,他们应该每回合在每个变量中损失一分:
warmth = warmth - 1;
hunger = hunger - 1;
thirst = thirst - 1;
代码超过 100 行,所以除非有人询问,否则我不会粘贴整个代码。如果任何变量为 0,则游戏结束:
if (hunger = 0){
cout<< "You starved!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
if (thirst = 0){
cout<< "You became dehydrated!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
if (warmth = 0){
cout<< "You froze!"<< endl;
cout<< "Game over!"<< endl;
return 0;
}
【问题讨论】:
-
顺便说一句,当你得到编译错误它指向特定的行时,你至少应该粘贴编译器给你的确切消息和它指向的行。