In console: how to make part of console window not moveable?

Hello,
I want to test my programming skills(and also learn few things), so I decided to create text-based Role-playing game in c++.

Here's how I'd like it to look like:

||||||||||||||||
| |
| game |
| window |
| |
| |
|--------------|
| commands|
|_________|

Well, I'm not perfect at making pictures, also i can't make it look like a window, but it's console window, I hope you know what I mean :)
Anyway. I want it to have an area separated by '-' or maybe line(i just don't know how to create one).
It should look a bit like my picture; you can see anything that program outputs in game window(for example "Welcome to my first RPG game" or "You see troll"), and your commands are written in "commands" section(and this section doesn't move at all). My main problem is this section. I don't know how to make one, and than make it not moveable, so when you write your commands game window updates, but commands area just clears itself(so when you type for example "go", it doesn't stay there, obviousely). Is there any way I can do that, or achieve something close enough to use it?

Thanks for your help.
Last edited on
You could use the following function:
1
2
3
4
5
6
7
8
9
10
11
12
13
void gotoXY( int x, int y )
{
	HANDLE output_handle;

	COORD pos;

	pos.X = x;
	pos.Y = y;

	output_handle = GetStdHandle( STD_OUTPUT_HANDLE );

	SetConsoleCursorPosition( output_handle, pos );
}


Pass the function 2 int's, and the console cursor will move to that location. Re-write the 'Commands' section and the top can stay the same (:
Doing what you want is a surprisingly black art. Fortunately, the Curses library (google NCurses and PDCurses, depending on your OS) has stuff that does just that.

All your console I/O needs to go through the Curses methods, though. (Which is reasonable.)
@Lynx876 - the problem with your idea(if i understand what you did there) is that user will see area with command going up, so if he scrolls up, he can see that it stayed there - and I want to avoid it(no clearscreen though).

I'll check Curses library, looks like I'm gonna have much more work doing it, but it's surely worth it. Thanks for help.
I've used this function a few times to clear parts of the screen.

Something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <conio.h>
#include <Windows.h>

void gotoXY( int x, int y )
{
	HANDLE output_handle;

	COORD pos;

	pos.X = x;
	pos.Y = y;

	output_handle = GetStdHandle( STD_OUTPUT_HANDLE );

	SetConsoleCursorPosition( output_handle, pos );
}


int main( int argc, char *argv[] )
{
	const int consoleWidth = 80;
	const int consoleHeight = 23;

	for( int y = 10; y < consoleHeight;  ++y )
	{
		for( int x = 2; x < consoleWidth - 2; ++x )
		{
			gotoXY( x, y );
			std::cout << '@';
		}
	}

	gotoXY( 5, 3 );
	std::cout << "Just moved here and printed this message.";

	// pause the program
	_getch();

	return 0;
}


Run this code. With a nested for-loop you can clear a certain area. I filled the area with @'s so you could see.

Here's what it looks like:
http://i749.photobucket.com/albums/xx132/Bigdave876/Cpp/gotoXY.jpg
He doesn't want to clear the screen. He wants sub-windows that are separate, independent pieces of the screen.
> I'll check Curses library, looks like I'm gonna have much more work doing it, but it's surely worth it.

Yes, learning to use curses is certainly worthwhile. But your aim is: 'I want to test my programming skills(and also learn few things), so I decided to create text-based Role-playing game in c++'. So do it in two steps.

In the first phase, focus on the logic of the game that you want to write, and nothing else; C++ skills without screen management getting in the way. Use a fixed size memory buffer to simulate the screen; for instance std::vector<std::string> screen( 25U, std::string(80U,' ') ) ; for an 80x25 screen. Perform all output to this abstract screen (use a std::ostringstream where required) and when you want to display it, copy it to std::cout. Run the program in a console sized to 80X25. It will scroll, but other than that will provide fixed command area that you want.

Once you have got this first part working correctly, port it to use curses, with all the associated bells and whistles. You might want to consider using a C++ wrapper library over curses - for instance NDK++ http://ndk-xx.sourceforge.net
I disagree. I don't see any reason he can't do both at once.
Topic archived. No new replies allowed.