开发者

How do I save the character occupying a certain space in curses?

开发者 https://www.devze.com 2023-01-23 11:36 出处:网络
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

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 curs开发者_如何学Pythones documentation. I'm looking for a function like this:

int storage = mvsavechar(1,1);

Does any such function exist?


You're looking for mvinch():

int storage = mvinch(1, 1) & A_CHARTEXT;


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消