如何保存诅咒中占据一定空间的角色?
我开始尝试用C++用curses制作一些简单的控制台游戏,我的第一个项目只是一个可以在其中走动的大房间。我想我将通过让程序保存方块的状态来实现步行角色正在行走,所以当他走到下一个方块时,它可以恢复那里的任何东西。问题是,我不知道如何将某个位置的角色保存到变量中,令我惊讶的是,我似乎找不到任何全面的诅咒文档。我正在寻找这样的函数:
int storage = mvsavechar(1,1);
是否存在这样的函数?
I'm beginning to try making some simple console games in C++ with curses, and my first project is just a large room to walk around in. I figure I'm gonna implement walking by having the program save the state of the square that the character is walking on, so when he walks onto the next square, it can restore whatever was there. Problem is, I don't know how to save the character at a certain position to a variable, and to my surprise I can't seem to find any comprehensive curses documentation. I'm looking for a function like this:
int storage = mvsavechar(1,1);
Does any such function exist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在寻找 mvinch():
You're looking for mvinch():
您需要将房间的数据存储在程序中的某种数据结构中。 Curses 是一个输出库。
You're going to need to store the data for the room in some sort of data structure in your program. Curses is an output library.
我将屏幕状态存储在 80x24(或其他)字符数组中。但您可能会调整阵列的大小以匹配“大房间”的尺寸。如果房间非常大,您可以使用(例如)坐标和内容的链接列表来存储稀疏数组的等效项。
Curses 可能没有您想要的功能,因为早期的终端可能没有询问屏幕内容的能力。
我对诅咒了解不多,如果诅咒保留了屏幕内容的详细信息,那么您想要的可能是可能的 - 但这似乎不太可能。
I'd store screen state in a 80x24 (or whatever) char array. But probably you'd size the array to match the dimensions of your "large room". If the room were extremely large, you could store the equivalent of a sparse array by using (for example) a linked list of coordinates&contents.
Curses probably doesn't have the function you want because early terminals probably didn't have the capability of being interrogated about screen contents.
I don't know much about curses, what you want might be possible if curses maintained details of screen contents - but that seems very unlikely.