How to redirect user?

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.

Thanks!
Last edited on
Have the starting point as a function, when time comes to redirect the user, simply call the function with the user's current data/progress
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.
Use goto hehe (bad choise)
@ceci

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.

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
#include <iostream>
#include <windows.h>

using namespace 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;

	else
	 do
	 {
		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 );
}
Last edited on
Topic archived. No new replies allowed.