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.
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;
}
}
returntrue;
}
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;
}
}
returntrue;
}
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.
#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.
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.