Question

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?

Was it helpful?

Solution

You're looking for mvinch():

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top