我正在努力做一个非常基本的文本冒险来测试我的基本技能.基本运动提示用户输入,如果它匹配某些字符串,则更改其坐标.我知道,这很愚蠢.但是if,else if,else匹配他们的反应总是返回else,即使你输入的字符串匹配的一个.
string action;
string west = "go west";
string east = "go east";
string north = "go north";
string south = "go south";
string prompt = "Don't just stand around with your dagger in your ass! Do something! ";
//i wrote a bunch of setup story here, it's irrelevant text output
int vertical = 25;
int horizon = 20;
//action begins
start:
{
cout << "What do you do?" << endl;
cin >> action;
if (action == south)
{
vertical = vertical - 5;
goto descriptions;
}
else if (action == east)
{
horizon = horizon + 5;
goto descriptions;
}
else if (action == west)
{
horizon = horizon - 5;
goto descriptions;
}
else if (action == north)
{
vertical = vertical + 5;
goto descriptions;
}
else
{
cout << prompt << "(Try typing \"go\" followed by a direction)" << endl;
goto start;
}
description:
//i put a bunch of if, else if, else stuff about coordinates describing the area down here.
Run Code Online (Sandbox Code Playgroud)
当我输入"go east"或"go north"时,它会打印关于匕首和驴子的提示字符串,只有在我输入其他内容时才会打印.我究竟做错了什么?为了澄清,我在OS X 10.10.3上使用Xcode.
| 归档时间: |
|
| 查看次数: |
85 次 |
| 最近记录: |