- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
所以,我有一个基于文本的小游戏,我的大部分东西都设置好了,但如果关键字不正确,它会重置,你必须再次搜索第一个关键字才能继续沿着路径线程.此外,我在 if 语句的最后添加了 sleep ,以进一步询问如何将延迟键入效果应用于 cout 语句。如果不可能,无论如何谢谢。让我知道,我喜欢一些输入,并希望在这里摆脱困境。
char intro[] = "INTRO_TEXT";
for (int i = 0; i < sizeof(intro); i++) {
cout << intro[i];
Sleep(30);
}
char result00[] = "RESULT_TEXT00";
char result01[] = "RESULT_TEXT01";
char result02[] = "RESULT_TEXT02";
int i = 1;
while (i < 5) {
string path00;
cin >> path00;
if (path00 == "example1") {
cout << result00 << endl;
string path01;
cin >> path01;
if (path01 == "example2") {
cout << result01 << endl;
string path02;
cin >> path02;
if (path02 == "example3) {
cout << result02 << endl;
Sleep(30);
}
else {
cout << "Not a keyword." << endl;
int i = 0;
}
}
}```
最佳答案
听起来您可能想要以不同方式构建您存储游戏世界的方式。树可能是一个不错的选择,这样您就可以简单地存储对您在树中所处位置的引用。
这是一个示例实现,它可以让用户在不同的“房间”之间来回走动,并且在操作未知时不会丢失位置:
#include <map>
#include <string>
#include <iostream>
struct Room {
std::map<std::string, Room*> actions;
std::string description;
};
Room *buildRooms() {
Room *startingRoom = new Room();
startingRoom->description = "You are in a dimly lit room. You see doors to the north and south";
Room *northRoom = new Room();
northRoom->description = "You are in a closet. There is a door to the south";
northRoom->actions["south"] = startingRoom;
startingRoom->actions["north"] = northRoom;
Room *southRoom = new Room();
southRoom->description = "You are in a field. There is a building with a door to the north.";
southRoom->actions["north"] = startingRoom;
startingRoom->actions["south"] = southRoom;
return startingRoom;
}
void playGame() {
Room *currentRoom = buildRooms();
while(currentRoom != nullptr) {
std::cout << currentRoom->description << std::endl;
std::string userInput;
std::cin >> userInput;
Room *nextRoom = currentRoom->actions[userInput];
if(nextRoom == nullptr) {
std::cout << "Not a keyword" << std::endl;
} else {
currentRoom = nextRoom;
}
}
}
重要的区别在于您所在的位置(指向 currentRoom 的指针)存储在游戏循环之外。
对于延迟打印效果,您可以编写一个函数,它接受一个字符串并在字符之间延迟打印出来,然后在您想要该文本效果的任何地方使用它代替 std::cout。
例如:
void say(std::string text) {
for(unsigned int i = 0; i < text.length(); i++) {
std::cout << text.at(i);
Sleep(30);
}
}
关于c++ - 重复和空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55887135/
我有这个代码来查找这个模式:201409250200131738007947036000 - 1,在文本内 final String patternStr = "(\\d{
我正在尝试使用正则表达式清除一些用户输入,以删除 [ 和 ] 并删除任何大于 1 个空格的空格。但我似乎无法实现我想要的效果。这是我第一次使用正则表达式,所以我对如何写出来有点困惑。 (preg_re
我正在尝试构建这个简单的正则表达式来匹配 Java 中的单词+空格,但我在尝试解决它时感到困惑。该网站上有很多类似的示例,但答案大多给出了正则表达式本身,而没有解释它是如何构造的。 我正在寻找的是形成
好吧,我已经阅读了很多建议如何消除多余空间的帖子,但无论出于何种原因,我似乎无法将这些建议应用到我的系统中,所以我在这里寻求您的帮助。 这些是我代码的最后几行: for line in rli
所以我正在我的测试存储上学习网页抓取,但我不确定如何正确地从“sizes”数组中删除空的新行。 const $ = cheerio.load(body) $('div.lis
这个问题已经有答案了: How to prevent invalid characters from being typed into input fields (8 个回答) 已关闭 9 年前。 是
有人知道如何让扫描仪忽略空间吗?我想输入名字和第二个名字,但扫描仪不让我输入,我想保存全名 String name; System.out.print("Enter name: "); name =
这个问题在这里已经有了答案: Make Vim show ALL white spaces as a character (23 个回答) 关闭 8 年前。 VIM(使用 Solarized Dar
我想使用 StreamTokenizer 从 java 文件中提取名称。我已将空格设置为逗号 inputTokenizer.whitespaceChars(',', ','); 但是,
我正在使用此代码逐行读取 txt 文件。 // Open the file that is the first command line parameter FileInputStream fstre
我似乎无法弄清楚我需要的正则表达式。这就是我想要实现的目标: {ANY CHAR} + @javax.persistence.Column(name = "{ANY 30 CHARS}") + {AN
我正在运行 StyleCop(顺便说一句,如果你想提供高质量的代码,我完全推荐它)... 我有这条线 [System.Xml.Serialization.XmlRootAttribute(Namesp
我刚刚更新到 PhpStorm 2016,我突然注意到,每次我按 Ctrl + S 保存文件时,它都会删除我在测试这段代码后按下以继续编写的空格/制表符。 请帮忙,这对我来说很烦人,因为我在每一行代码
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 Improve th
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度的了解。包括尝试的解决方案、为什么它们不起作用以及预期结果
我已经看过几十个关于这个主题的问题和答案,但我仍然无法解决我的问题。 我在我的代码中使用了一个外部 ffmpeg 转换器,我将文件路径作为参数传递,如下所示: OutputPackage oo = c
谁能详细解释一下它们是什么以及它们之间的区别。提前致谢。 最佳答案 转义序列是代表其他内容的字符序列。例如(“\n” = 新行,“\?” = 问号等)。有关更详细的列表,请检查:https://en.
我无法从我的 javascript 文本中删除换行符。这是我正在处理的数据示例: 0: "Christian Pulisic" 1: "↵" 2: "From Wikipedia, the free
我有一个问题 - 我似乎无法从字符串的开头/结尾删除新行/空格。我在正则表达式的开头和结尾使用 \s ,甚至在获取字符串后使用 .trim() ,但无济于事。 public void extractI
我是 php 的新手,我正在尝试将一系列变量添加到 html 超链接中。但是,任何返回空格的变量都会弄乱超链接。 Grants Test
我是一名优秀的程序员,十分优秀!