重绘屏幕并擦除已有内容
我需要一些帮助 - 我正在尝试使用 C++ 创建一个 roguelike,目前,我有一个非常简单的小屏幕,使用 void() 生成地图,使用“#”表示墙壁和“.”。用于地板。它可以通过比较一些映射玩家的 X 和 Y 值的整数来绘制玩家。 我什至有一个小平视显示器来显示玩家的统计数据。
但是,问题是,这一切都是使用典型的命令控制台窗口设计的,我开始认为我做错了。
我希望玩家通过使用数字键盘在我拥有的这个大空房间中移动 - 这很有效。通过使用 Switch,我调整 X 和 Y 玩家值,然后再次重绘屏幕。
问题就在这里。这实际上会重新重新绘制屏幕:每次我移动时,它都会重新添加 20 多条线。经过几次操作后,我得到了一个命令控制台窗口,其中包含数百行文本。
那么我做错了什么?是否有我不知道的命令可以清除屏幕?
或者我从一开始就做错了——例如,你必须按“回车”键才能输入你的命令,这是任何其他 roguelike 游戏中都没有的。我是一名新手程序员,因此非常感谢您的帮助!
谢谢你!
编辑: 好的,谢谢大家,我现在正在使用 PDCurses 并搜索文档来找出如何使用它!再次非常感谢!请有人给提出这个建议的人一个大大的勾! :D
I need some help - I'm trying to create a roguelike using C++, and at the moment, I have a very simple little screen going, with a void() that generates a map, using "#" for walls and "." for floors. It can draw the player by comparing some integers which map the X and Y values of the player.
I even have a little HUD which will display the player's stats.
But, the issue is, this is all being designed using a typical command-console window, and I'm starting to think I'm doing this wrong.
I want the player to move around this big empty room I have, by using the numpad -- this works. By using a Switch, I adjust the X and Y player value and then redraw the screen again.
Here's the issue. This actually redraws the screen all over again: it adds the 20-odd lines all over again, every single time I move. After a few moves, I have a command console window with text going for hundreds of lines.
So what am I doing wrong? Is there a command I don't know about to clear the screen?
Or am I doing this wrong from the start -- for instance, you have to press 'enter' to input your command, something that's not in any other roguelike. I'm a novice programmer, so any and all help is appreciated!
Thankyou!
Edit: Okay, thanks guys, I am now using PDCurses and trawling the docs to work out how to use the thing! Thanks again so much! Somebody please give the guy who suggested this a big tick! :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你用什么方法来绘制屏幕,只是普通的iostream?对于此类工作,通常建议使用名为 curses 的库。它可以让您在屏幕上的任何位置绘制文本,而无需滚动或重新绘制整个屏幕。
What method are you using to draw the screen, just normal iostream? For this kind of work a library called curses is normally recommended. It would let you draw text anywhere on the screen without scrolling or redrawing the entire screen.
我不知道有什么可靠的方法来实现可移植性,也许尝试寻找一些面向控制台的库......无论如何,在 Windows 下你仍然可以使用 system("cls");
I don't know of any reliable way to do it with portability, maybe try looking for some console oriented lib... Anyway under Windows you can still use system("cls");
您可以使用 ansi 转义序列:printf ("\33[2]")。
You can use the ansi escape sequence: printf ("\33[2]").