Changing screens

I am almost done my text based game. The other day our teacher showed us a game from a few years ago.

In the game if you chose an option and a new .cpp loaded it basically switched to a different screen.

This made it so that the game wasn't just scrolling down as it went on. However in true teacher fashion he told me to look online when i asked how he did it. Since i am not sure what exactly i should be using in my search to find it... i was wondering if anyone here would know to what he was referring to?

Even if it is to give me direction in my search, any help will be most appreciated.
Google: Curses C++
What do you mean by switching screens? It cleared the screen inbetween pages of output?
The example game had a title screen, if you chose to do something nothing of the title output remained.

you could only see the output of the next cpp file
i forgot to mention that this is a win 32 console application using just cout's to display the game.
what i would like it to do is when i go, for example, from bridge.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
bool bridge()
{
	

	int choice =0;

	while  (choice != 10)
	{
		cout<< "You find your self in a room filled with electronics..\nRight away you realise that your on an alien spaceship..alone..\n\n";

		wait();

		cout<<"What will you do "<< player.GetName()<<"?\n\n";

		
		cout<< "1: Look at 'damage console'\n";
		cout<< "2: Look at 'navigational console' \n";
		cout<< "3: Grab Triphasic Control Chips\n";
		cout<< "4: Grab Isolinar Control Rod\n";
		cout<< "5: Use Maitenance tube to Astormetrics\n";
	
		cout<< "9: Check Current Inventory\n";
		
		cout<< "10: Exit Game\n";
		cout << "->";

		cin>> choice;
		cin.ignore(10,'\n');

		cout<< endl;

		switch(choice)
		{
		
		case 1:
			{
				cout<< "you look at the console...\n";
				cout<< "It shows the current damage to the ship...\n\n";	
					break;
			
			}
		case 2:
			{
				cout<<"You see the a discription of the course your ship is taking...\nHowever it is fuzzy and non-discriptive...\n\n";
					
				break;
			}
		case 3:
			{
				cout<<"You collected the Transphasic Control Chips!\n\n";
				inventory.push_back("Chips");
				break;
				
			}
		case 4:
			{
				cout<<"You collected the Isolinar Control Rod!\n\n";
				inventory.push_back("Rod");
				break;
				
			}
		case 5:
			{
				astrometrics();
				break;
			}
		case 9:
			{
				cout<<"Your current inventory has:\n\n";
				for (int i=0; i < inventory.size(); i++)
				{
					cout<<inventory[i]<<" ";
				}
			cout<<"\n\n";
			}
		default:break;
		}
	}
	return true;
}


to say engine core.cpp

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
bool enginecore()
{

	int choice = 0;

	while(choice != 10)
	{	

		cout<< "You find yourself inside what seems to be a navigations area...\nIt looks severly damaged and parts sem to be missing from areas\n\n";

		wait();
		
		cout<<"What will you do "<< player.GetName()<<"?\n\n";

		cout<< "1: Insert Palladium Core\n";
		cout<< "2: Insert Plutonium Core \n";
		cout<< "3: insert Unubtainium Core\n";
		cout<< "4: Grab Crystaline Refractor\n";
		cout<< "5: Grab Memory Core Gamma\n";
		cout<< "6: Return to the Transfer Tube\n";

		cout<< "9: Check Current Inventory\n";
		cout<< "10: Exit Game\n";
		cout<< "->";

		cin>> choice;
		cin.ignore(10,'\n');

		cout<< endl;

		switch(choice)
		{
		case 1:
			{
				if (!plucomplete && !uncomplete)
				{
					if(Check_Inv("PalCore"))
					{
						cout<<"You have inserted the Palladium Core!\n\n";
						palcomplete = true;
					}
					else
					{
						cout<<"The Palladium Core is not in your inventory!\n\n";
					}
				}
				else 
				{
					cout<<"There is already a core in the Engine!\n\n";
				}
				break;
			}
		case 2:
			{
				if (!palcomplete && !uncomplete)
				{
					if(Check_Inv("PluCore"))
					{
						cout<<"You have inserted the Plutonium Core!\n\n";
						plucomplete = true;
					}

					else
					{
						cout<<"The Plutonium Core is not in your inventory!\n\n";
					}
				}
				else
				{
					cout<<"There is already a core in the engine!\n\n";
					break;
				}
			}
		case 3:
			{
				if (!palcomplete && !plucomplete)
				{
					if(Check_Inv("UnCore"))
					{
					 cout<<"You have inserted the Unubtainium Core!\n\n";
					 end5();
					}
					else
					{
						cout<<"The Unubtainium Core is not in your inventory!\n\n";
					}
				}
					break;
				}
		case 4:
			{
				inventory.push_back("Refractor");
				break;
			}
		case 5:
			{
				inventory.push_back("Gamma");
				break;
			}
		case 6:
			{
				transittube();
				break;
			}

		case 9:
			{
				cout<<"Your current inventory has:\n\n";
				for (int i=0; i < inventory.size(); i++)
				{
					cout<<inventory[i]<<" ";
				}
			cout<<"\n\n";
			}
		default:break;
			}
			}
			return true;
		}


i instead of showing the new cpp file under the last one, i want only the cpp being currently displayed to be on screen. Replaceing as it were so that it isn't just adding and adding and scrolling down every time something happens.
Just clear the screen before output: http://cplusplus.com/forum/articles/10515/#msg49080

Personally I like to use both of Duoas' examples in a single function:
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifdef _WIN32
# include <windows.h>
#else
# include <unistd.h>
# include <term.h>
#endif

int clearscreen()
{
#ifdef _WIN32
	HANDLE				hstdout;
	CONSOLE_SCREEN_BUFFER_INFO	csbi;
	DWORD				count;
	DWORD				cellcount;
	COORD				homecoords = { 0, 0 };

	if ((hstdout = GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE)
		return -1;

	/*
	 * Get buffer cell count
	 */
	if (!(GetConsoleScreenBufferInfo(hstdout, &csbi))
		return -1;
	cellcount = (csbi.dwSize.X * csbi.dwSize.Y);

	/* 
	 * Fill the buffer with spaces
	 */
	if (!(FillConsoleOutputCharacter(hstdout, (TCHAR)' ', cellcount,
					 homecoords, &count)))
		return -1;

	/*
	 * Set buffer attributes
	 */
	if (!(FillConsoleOutputAttribute(hstdout, csbi.wAttributes, cellcount,
					homecoords, &count)))
		return -1;

	/*
	 * Set cursor position home
	 */
	SetConsoleCursorPosition(hstdout, homecoords);
#else
	/*
	 * Create a terminal if none exists
	 */
	if (!(cur_term)) {
		int result = 0;
		setupterm(NULL, STDOUT_FILENO, &result);
		if (result < 0) {
			return -1;
		}
	}

	/*
	 * Clear the screen
	 */
	putp(tigetstr("clear"));
#endif
	return 0;
}

On UNIX systems, add -lcurses to the command-line to link the curses library, you'll need it for those functions. On Windows you need to link the Windows API which I think will be done automatically for you.
Last edited on
Does it also then print the cout of the next cpp in its place? and is this applicable to visual studio 2008
idealy i want everything that i do on the cabin screen to remain till i access another area of my game which is in a separate cpp file. That way it doesn't just add and add causing it to just become one longer and longer output.

To build GUI using C++ really depend on the environment.

For Linux/Unix Curses are not "beautiful" enough. I would go for X Windows/Motif.

For Windows, it is simply .NET C# or the earlier version called MFC or even earlier Windows SDK :(
For a text-based game, use NCurses. You may already have it installed, actually.
Some reading to get started: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
@soghuanh,
sohguanh wrote:
For Linux/Unix Curses are not "beautiful" enough. I would go for X Windows/Motif.

I strongly disagree. [N,PD]Curses is excellent, and cross-platform. Why use Xlibs or Motif? They're not cross-platform and he's not writing a GUI.

sohguanh wrote:
For Windows, it is simply .NET C# or the earlier version called MFC or even earlier Windows S

Why? You can just use a cross-platform library like Qt, GTK+ or wxWidgets.
Why? You can just use a cross-platform library like Qt, GTK+ or wxWidgets.


Thanks for providing me additional information on Windows GUI. Qt, GTK+ and wxWidgets are new sources of information for me.
Fair enough.
Topic archived. No new replies allowed.