Hi! I'm trying to program a simple game for a project and I was wondering how I redirect the player back to the main menu?
To elaborate, this is a game where the player must choose between doors, solve a riddle/puzzle, then proceed to the next room and I was wondering how I can have the wrong doors redirect to the starting point, giving the player the option of trying again or ending the game.
If I were you, I'll manage it like 'pages' and have events to change a page.
so you'll be able to change to whatever pages you want.
Just delete current page and call new page.
Maybe pages defined by each classes, or maybe objects.
Here's one way. It's just a quick program I threw together, but it should give you ideas on how to add the option to your program. Ask if you need help on it.
#include <iostream>
#include <windows.h>
usingnamespace std;
void ClearScreen(); // Clear the screen, what else ;)
int main()
{
bool play = true;
bool dead = false;
int go, door,level;
do
{
level = 1;
dead = false;
ClearScreen();
cout << "Do you wish to..." << endl << endl;
cout << "1 > Enter the 'Rooms of Dooms'?" << endl;
cout << "2 > Run home and hide under your bed ?" << endl;
cin >> go;
if( go == 2)
play = false;
elsedo
{
door = 1+rand() %2; // Didn't bother using srand() first.
ClearScreen();
cout << endl << endl << "Level # " << level << endl << endl;
cout << "Go through the.." << endl;
cout << "1 .. Left door ?" << endl;
cout << "2 .. Right door ?" << endl;
cin >> go;
if(go==door)
{
cout << "Wow. You made it to the next level..." << endl;
level++;
}
else
{
cout << "Oh oh. You died a horrible death.. Better luck in the next life." << endl;
dead = true;
}
Sleep(2500);
}while (!dead);// Keeps giving optio to go right or left UNTIL you die. (Sorry. Nice knowing you!!)
}while (play);// Shows menu until you pick #2
cout << "What a WIMP!! Afraid of a little (or maybe a LOT ) of PAIN!! Ha ha ha...." << endl << endl;
return 0;
}
void ClearScreen()
{
DWORD n;
DWORD size;
COORD coord = {0};
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
GetConsoleScreenBufferInfo ( h, &csbi );
size = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
GetConsoleScreenBufferInfo ( h, &csbi );
FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
SetConsoleCursorPosition ( h, coord );
}