我正在开发一个文本冒险游戏,菜单屏幕类似于此。
******************************
| Hello, Adventurer |
| |
| What is your name? |
******************************
Name: 所以牧师会对这个名字眨眼。但是当玩家输入这个名字时,它会像这样显示
例如,我输入了"John“作为名称。
******************************
| Hello, John |
| |
| Welcome to Text-RPG |
******************************但是,它会在一个单独的部分打印上面的文本。
是否可以将第一个文本集替换为第二个文本集,而不需要单独的部分?
发布于 2016-03-05 15:40:26
使用OSX终端,您可以使用所谓的"ANSI转义序列“,包括:
\033[2J
\033[H它分别清除屏幕并将光标移动到"home“位置(左上角)。如果您正在编写一个简单的程序,它打印一些信息,然后提示输入,它可以相当好地重新绘制整个屏幕之间的提示。top程序所做的事情如下:
cout << "\033[2J\033[H";大多数终端在发送表单提要('\f'或^L)时不清除显示,因为大多数终端是基于VT100仿真的。OSX终端并不是这种罕见的例外情况之一。
进一步读:
发布于 2016-03-05 11:18:32
你在游戏中使用图形吗?如果是的话,您可以在什么时候向用户显示框架,但是如果您是初学者,那么您现在还没有一个非常准确的解决方案。然而,有一个简单的技巧可以在你的情况下起作用。
发布于 2016-03-05 16:17:39
1.You can try the logic of displaying newlines as follows
#include <iostream>
using namespace std;
void clear_scr()
{
/*printing 100 new lines to clear everything on screen*/
cout << string( 100, '\n' );
}
int main()
{
cout << "Clearning Screen" << endl;
clear_scr();
cout<<"SCREEN CLEARED"<<endl;
return 0;
}
2. I have seen this code on various websites. This might work but i am not sure about it. Try it.
In Windows:
#include <cstdlib>
int main() {
std::system("cls");
return 0;
}
In Linux/Unix:
#include <cstdlib>
int main() {
std::system("clear");
return 0;
}https://stackoverflow.com/questions/35813318
复制相似问题