I'm kind of new to the forums so i thought i would say hi to everyone.

This is sort of just a hello message and a quick question about functions.
I am in the progress of making my own text based role playing game and doing quite well but i have run into a slight problem with being able to switch between functions when trying to reaccess the main menu. My question is should functions be created outside the main one or inside it. Right now i have them above the main function and they are working fine by when i try to use a goto from the character status page back to the main menu which is currently inside the main fuction that is where I noticed the first problem.

I would like to put the code on here but its alittle bit too long to fit in the post.
Functions all always go outside of main. main itself is a function, and it doesn't make sense to put one function into another.

Also, don't use goto. There are probably a million betters way of doing it than using goto.
I think you dont understand global and local scope, try and research that.
I only use goto generally to return to the top of a switch because some of the options its a chose your own adventure style rpg so there is alot of multiple choices. Which have boolean checks to see if you have already choosen that option before with the exception of free movement. My problem is you know how the program starts at the top and works its way down to the end of all of the code and main and then exits. I need to find a way to loop back up in the program code if one wants to go back to the main menu and then back into the game.
That's just some simple nested loops. ;)
Possibly im still fairly new at this, im trying to seperate my game into several functions.

main function for the application

MainMenu() <--- implemented this recently due to midi delay i want to preload in main before menu pops up

HelpMenu() For help information on playing game & commands.

NewGame() Starts new game this is where most of my code is

LoadGame() used to load a game file which will then send to you a special text for re entry into game environment

SaveGame() for saving the variables for the character information and boolean checks

ExitGame() Exit Game

PlayerStatsDisplay() Shows character name,level,exp,hitrate,attack,defense,gold, and in the future an inventory system
Last edited on
I will post my code in several sections:

This is the main code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int _tmain(int argc, _TCHAR* argv[]) // Main Program Fuction
{
	int MainExit;
	cout << "Starting up the game....\n";
	mciSendString("open C:/KingdomOfMythos/Midi/MythosIntro.mid" ,NULL,0,NULL); // Open Midi Music
	mciSendString("open C:/KingdomOfMythos/Midi/MythosMusic1.mid" ,NULL,0,NULL); // Open Midi Music
	mciSendString("play C:/KingdomOfMythos/Midi/MythosIntro.mid" ,NULL,0,NULL); // Play Midi Music
	MainMenu();
	
	cout << "What do you wish to do? <1 = Main Menu> <2 = Exit>\n";
	cout << "Please make a selection <1-2>\n";
	cin >> MainExit;
	if (MainExit == 1)
	MainMenu();
	else if (MainExit == 2)
	ExitGame();
	return 0;
}
This is the MainMenu()


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
int MainMenu() // Main Game Menu
{
	int MainMenuOption = 0; // Variable for main menu selection
	HANDLE hConsole; // Code for colored text
	hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Code for colored text
	{
	SetConsoleTextAttribute(hConsole, 12); // Colored Text Red
	}	
	cout << "                             -=KINGDOM OF MYTHOS=-\n";
	cout << "                           Choose Your Own Adventure\n";
	cout << "                             (c) 2010 Shawn M. Naef\n";
	cout << "                               Version 1.0 Alpha\n";
	cout << "\n\n";
	{
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
	cout << "                                  MAIN MENU:\n";
	cout << "                                 ============\n";
	cout << "                                 1: New  Game\n";
	cout << "                                 2: Load Game\n"; 
	cout << "                                 3: Save Game\n";
	cout << "                                 4: Help Menu\n";
	cout << "                                 5: Char Stat\n";
	cout << "                                 6: Exit Game\n";
	cout << "\n\n";
	cout << "Please make a selection <1-6>.\n";
	cin >> MainMenuOption;
	if (MainMenuOption >= 6)
		ExitGame();
	else if (MainMenuOption == 5)
		PlayerStatsDisplay();
	else if (MainMenuOption == 4)
		HelpMenu();
	else if (MainMenuOption == 3)
		SaveGame();
	else if (MainMenuOption == 2)
		LoadGame();
	else if (MainMenuOption == 1)
		NewGame();
	else if (MainMenuOption <= 0)
		ExitGame();
	return 0;
This is the Exit its not really fully done yet may want to modify the way stuff interacts after i solve the loop issue.

1
2
3
4
5
6
int ExitGame()  // Exits the game
{
	cout << "See you again. Thanks for playing!\n";
	cout << "Press <e> and hit enter to exit program.\n";
	cin  >> Exit;
	return 0;

NewGame()

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
int NewGame()  // Starts a new game
{
	HANDLE hConsole; // Code for colored text
	hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Code for colored text
	bool Option04x000 = (false); // Bool for switch options - integrity check
	bool Option05x000 = (false); // Bool for switch options - integrity check
	bool Option03x001 = (false); // Bool for switch options - integrity check
	bool Option04x001 = (false); // Bool for switch options - integrity check
	bool Option05x001 = (false); // Bool for switch options - integrity check
	
	mciSendString("stop C:/KingdomOfMythos/Midi/MythosIntro.mid" ,NULL,0,NULL); // Stop midi file
	mciSendString("open C:/KingdomOfMythos/Midi/MythosMusic1.mid" ,NULL,0,NULL); // Open midi file
	mciSendString("play C:/KingdomOfMythos/Midi/MythosMusic1.mid" ,NULL,0,NULL); // Play midi file
	{
	SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
	}
	cout << "\nWELCOME TO THE KINGDOM OF MYTHOS!\n\n";
	{
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
	cout << "\nPlease enter your characters first name only <a-z> and hit enter.\n";
	cin >> PlayerName;
	cout << " __________________________________________________________________________ \n";
	cout << "| ________________________________________________________________________ |\n";
	cout << "||                                                                        ||\n";
	cout << "|| Greetings! And welcome to the Kingdom Of Mythos " << PlayerName <<".\n";
    cout << "|| You have just completed your royal training to become a knight. The    ||\n";
	cout << "|| ship bound for the royal capital Mythos has docked. The sun is shining ||\n";
	cout << "|| brightly and you can hear the waves crashing. The ships captain calls  ||\n";
	cout << "|| out to the passangers. Its time to depart.                             ||\n";
    cout << "||________________________________________________________________________||\n";
	cout << "|__________________________________________________________________________|\n\n";
	cout << "What do you do now?\n\n";
	cout << "Your Current Position Is:";
    {
	SetConsoleTextAttribute(hConsole, 9); // Colored Text Blue
	}
	cout << " [0,0,0] Port Mythos Docks.\n\n";
    {
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
OPT000:	
	cout << "Your Options Are:\n"; // Goto Option 000
	{
	SetConsoleTextAttribute(hConsole, 9); // Colored Text White
	}
	cout << "1: Move   East      [ 0,0,1 ] Sandy Beach\n";
	cout << "2: Move   South     [ 0,1,0 ] Dark Alley\n";
	cout << "3: Move   Southeast [ 0,1,1 ] Royal Capital Mythos\n";
	cout << "4: Action Examine Wooden Barrel\n";
	cout << "5: Action Explore Port Mythos Docks\n";
	{
	SetConsoleTextAttribute(hConsole, 12); // Colored Text Red
	}
	cout << "WARNING:";
	{
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
	cout << " Once you leave the docks you will be unable to return.\n\n";
	cout << "Please make a selection. <1-5>\n";
ERR000: // Goto Error 000
	cin >> OPT000; // Cin Input Switch Menu 000
	switch (OPT000) // Switch Menu 000
	{
	case 0: cout << "\nIncorrect Selection\n";
			cout << "Please re-enter your selection. <1-5>\n";
	        goto ERR000;
	        break;
	case 5: if (!Option05x000)
			{
			cout << "\nYou decide to explore the docks and find an old sword. You equip it.\n\n";
			Option05x000 = true;
			goto OPT000;
			}
			else
			{
			cout << "\nYou have already explored here before. There is nothing of interest here.\n\n";
			goto OPT000;
			}
			break;
	case 4: if (!Option04x000)
			{
			cout << "\nYou find 25 gold pieces in the barrel.\n\n"; 
			PlayerGold = PlayerGold + 25; // Adds gold to players inventory
			cout << "You now have " << PlayerGold <<" gold pieces.\n\n"; // Displays current gold held by player
			Option04x000 = true;
			goto OPT000;
			}
			else
			{
			cout << "\nYou have already examined the wooden barrel. There is nothing of interest here.\n\n";
			goto OPT000;
			} 
			break;
	case 3: cout << "Royal Capital Mythos - TEMP";
	        cin >> Test;
		    break;
	case 2: cout << "Old Wooden Shack - TEMP";
	        cin >> Test;
		    break;
	case 1: cout << "You decide to take a stroll down to the";
	        {
			SetConsoleTextAttribute(hConsole, 9); // Colored Text Blue
			}
			cout << " [0,0,1] Sandy Beach.\n\n";
			{
			SetConsoleTextAttribute(hConsole, 15); // Colored Text White
			}
			cout << " __________________________________________________________________________ \n";
	        cout << "| ________________________________________________________________________ |\n";
	        cout << "||                                                                        ||\n";
			cout << "|| As you walk down the beach you can feel the spray of the waves on your ||\n";
			cout << "|| skin. The sound of the waves crashing on the sand and the smell of the ||\n";
			cout << "|| the salty breeze. You also notice the large number of birds and ocean  ||\n";
			cout << "|| critters crawling on the beach. After a few minutes of walking you     ||\n";
			cout << "|| come across an old wooden shack. There is a smoldering fire nearby.    ||\n";
			cout << "|| Upon further investigation you notice fresh footprints in the sand. It ||\n";
			cout << "|| appears there is an old hermit living here.                            ||\n";
			cout << "||________________________________________________________________________||\n";
	        cout << "|__________________________________________________________________________|\n\n";
			
			cout << "What do you do now?\n\n";
			cout << "Your Current Position Is:";
			{
			SetConsoleTextAttribute(hConsole, 9); // Colored Text Blue
			}
			cout << " [0,0,1] Sandy Beach\n\n";
			{
			SetConsoleTextAttribute(hConsole, 15); // Colored Text white
			}
OPT001:
			cout << "Your Options Are:\n";
			{
			SetConsoleTextAttribute(hConsole, 9); // Colored Text Blue
			}
			cout << "1:Move   East  [0,0,2] Dark Cave\n";
			cout << "2:Move   South [0,1,1] Royal Capital Mythos\n";
			cout << "3:Action Explore Old Wooden Shack\n";
			cout << "4:Action Examine Smoldering Fire\n";
			cout << "5:Action Dig In Sand\n\n";
			{
			SetConsoleTextAttribute(hConsole, 15); // Colored Text White
			}
			cout << "Please make a selection. <1-5>\n\n";
ERR001: // Goto Error 001
			cin >> OPT001; // Cin Input Switch Menu 001
		    switch (OPT001) // Switch Menu 001
			{
			case 0: cout << "\nIncorrect Selection\n";
					cout << "Please re-enter your selection. <1-5>\n";
					goto ERR001;
					break;
			case 5: cout << "TEMP5\n";
					goto OPT001;
					break;
			case 4: cout << "TEMP4\n";
					goto OPT001;
					break;
			case 3: cout << "TEMP3\n";
					goto OPT001;
					break;
			case 2: cout << "TEMP2\n";
					cin >> Test;
					break;
			case 1: cout << "Temp1\n";
					cin >> Test;
					break;
		   default: cout << "\nIncorrect Selection\n";
					cout << "Please re-enter your selection. <1-5>\n";
					goto ERR001;
					break;
			}
			 break;
	default: cout << "\nIncorrect Selection\n";
	         cout << "Please re-enter your selection. <1-5>\n";
		     goto ERR000;
	         break;
	}
	cout << "\n\n";
	cout << "End of Function() Error.\n";
	cout << "Press <e> to exit program.\n";
	cin >> Exit;
	return 0;
}
PlayerStatsDisplay()

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
int PlayerStatsDisplay() // Function that displays character information
{
	HANDLE hConsole; // Code for colored text
	hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Code for colored text
	{
	SetConsoleTextAttribute(hConsole, 15); // Colored Text Green
	}
	cout << "\n";
	cout << "                             ______________________\n";
	{
	SetConsoleTextAttribute(hConsole, 12); // Colored Text Green
	}
	cout << "                             CHARACTER STATUS PAGE:\n";
	{
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
	cout << "                             ______________________\n";
	cout << "                                                   \n";
	{
	SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
	}
	cout << "                             Name: ";
	{
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
	cout << "" << PlayerName <<"\n";
	cout << "                             ______________________\n";
	cout << "                                                   \n";
	{
	SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
	}
	cout << "                             Level: ";
	{
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
	cout << "" << PlayerLevel <<"\n";
	cout << "                             ______________________\n";
	cout << "                                                   \n";
	{
	SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
	}
	cout << "                             Experience: ";
	{
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
	cout << "" << PlayerExperience <<"\n";
	cout << "                             ______________________\n";
	cout << "                                                   \n";
	{
	SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
	}
	cout << "                             Gold: ";
	{
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
	cout << "" << PlayerGold <<"\n";
	cout << "                             ______________________\n";
	cout << "                                                   \n";
	{
	SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
	}
	cout << "                             Attack: ";
    {
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
	cout << "" << PlayerAttack <<"\n";
	cout << "                             ______________________\n";
	cout << "                                                   \n";
	{
	SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
	}
	cout << "                             Defense: ";
	{
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
	cout << "" << PlayerDefense <<"\n";
	cout << "                             ______________________\n";
	cout << "                                                   \n";
	{
	SetConsoleTextAttribute(hConsole, 10); // Colored Text Green
	}
	cout << "                             HitRate: ";
	{
	SetConsoleTextAttribute(hConsole, 15); // Colored Text White
	}
	cout << "" << PlayerHitRate <<"\n";
	cout << "                             ______________________\n\n";
	cout << "Press <r> and enter to return to main menu.\n";
	cin >> Test;
	int MainMenu();
	return 0;
}
*groans at console games*

The console is a terrible medium for games.

I swear I've been seeing more and more of this lately. I really should get around to writing an article about the alternatives.

EDIT:

The goto-riddled spaghetti code isn't helping either x_X
Last edited on
Misc Stuff Global Variables and Includes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//INCLUDES
#include "stdafx.h" // Include Starting File
#include <iostream> // Include In/Out Stream
#include <fstream>  // Include File Stream (For Save Files)
#include "windows.h" // Windows Dependencies
#include <string>    // Character String Support
#include <mmsystem.h> // Additional Support Sound/Color
#include <conio.h> // Additional Support Sound/Color
using namespace std; // std::cin std::cout

//GLOBAL VARIABLES BELOW
string PlayerName; // String used to store players name
int PlayerLevel = 1; // Not implemented yet
int PlayerExperience = 0; // Not implemented yet
int PlayerGold = 100; // Variable that stores players gold
int PlayerHitPoints = 10; // Not implemented yet
int PlayerHitRate = 25; // Not implemented yet
int PlayerAttack = 5; // Not Implemented yet
int PlayerDefense = 15; // Not Implemented yet
unsigned short int OPT000 = 0; // Selection int for Switch 000
unsigned short int OPT001 = 0; // Selection int for Switch 001
char Exit; // Character for exiting program in event of failure
char Test; // Test variable used for testing new additions of code 












I don't mind people giving me advice thats why im here.
@Disch

How can you say that my code is riddled its very neat and documented granted i need to comment some more of my code i just haven't gotten round to it yet, what i need to do now is form a loop system so i can access the menu from different parts of the game and always get back into it. Not sure how to do that though.

@Kyon

Yes i really am looking for advice, but you also need to understand that I'm new and i don't know every way of doing things. Right now my program accually works and functions as intended im sort of building it from the ground up as i go this is a work in progress i learn better by breaking peoples code down and harvesting the information i need and incorporating it into my code to do what i need to this is how i learn how the stuff works.


Infact ive already come up with a way to fix my problem until i learn more about looping and going between functions it may be easier for me to build my menu and other stuff within the new game function so that I can call up the menu and then return back to where I was without exiting, im thinking i should use the end of main function as the exit since that is how it seems to work.

@Disch ty and its np i know people on forums can get quite angry with all the stuff that goes on here. I'm not really worried about the work being complicated lets just say im not doin this for employment, any future plans to be a developer this is just a hobby and i gota say i got plenty of time on my hands! I love a good challenge xD. I restructured my program by putting it all in sub function and only using main to enter and exit the program that way i can use a goto for each subsection rather then seperate functions. Now i just need to creat my text area for reentry back into the game probably do a city inn or something and alittle extra text like walk outside which puts you back in the city since the variables will remain uneffected. some of the things i need to work on are storing the variables and putting them into a save file and loading them back into memory. More complex math algorithms for calculating dmg from static encounters, and experience system, inventory system are a good start. This will be the core of the game, the rest is just mostly writing.
Last edited on
Why is goto evil? Because it's an old fashion command that breaks up every common sense in OOP programming (or more specifically, in C++). It is only left in the language to keep it compatible with the less fancy C language. Random bracketing, improper tabbing and overuse of comments can easily make reading your code confusing. Because we are here to help you, you make it hard on us all. Since you know the layout from your program in the most abstract level, you understand what is done. Since we only have the "low-level" product of this, in source code, it's very hard to understand.
Every goto can be replaced by a loop. Goto is evil, I refer to:
http://www.tuxradar.com/content/programming-languages-melt-your-brain
Read the part about spaghetti.

Also:
Snaef98 wrote:
I don't mind people giving me advice thats why im here.
Snaef98 wrote:
How can you say that my code is riddled its very neat and documented granted i need to comment some more of my code i just haven't gotten round to it yet,


Finally, try editing your posts instead of placing new ones all the time.
Last edited on
I guess I wasn't being very helpful earlier. Sorry. I just get frustrated.

Since it seems like everybody is introduced to the console first, they all think "I should make a game in the console". And I find myself perpetually attempting (often in vain) to dissuade people from doing this, as it is a horrible, horrible path to go down. Almost to the point where you're actually doing yourself a disservice by wasting your time and energy.

If you're really interested in making game, I'd say you shouldn't bother learning all this crap you're messing with now. Playing midi this way, changing the console text color, etc (where did you even learn how to do that?). All of that malarchy is useless and wasted knowledge. You're better off just getting a lib designed for gaming (I often recommend SFML http://www.sfml-dev.org/ ) and making games with that. It's really not as difficult as it's perceived to be.

That said... here's some actual advise as to how you can improve:

How can you say that my code is riddled


several reasons (many related)

1) You have tangles of gotos
2) Your names are indescriptive
3) Your functions are doing to much / they're too large
3) You're hardcoding everything.

Gotos destroy rational program flow. When your program is hoping all around it makes the logic very hard to follow. Hard to follow logic means more bugs, harder to maintain code, messier code, and makes it extremely difficult for anyone else to figure out what is going on.

Sure the code might makes sense to you. But that's because you're the one who wrote it. And you wrote it recently. Try sitting on the project for a couple months, then come back to it after you've forgotten how the inner workings work. You'll find it's a lot harder to follow than you originally thought.


Your labels and names of things are not descriptive, only adding to the confusion. "ERR001", "OPT001", etc. As a general rule of thumb, if you're naming things with numbers like that, you're doing something wrong. (Of course this isn't always the case, but it usually is).


Your functions are too long. This is because they're doing too much. A function should do 1 task. If that task consists of several parts, then you should break down those parts into other functions. This makes the overall flow of logic much easier to follow... especially if you give the functions descriptive names. Plus if the function does a small, simple task, it's much easier to write and bugs are less likely.


You're hard-coding everything. Basically that means you're doing this:

1
2
3
4
5
6
7
8
if( player_is_in_the_forest )
{
  // do forest stuff here
}
else if( player_is_in_the_mountains )
{
  // do mountain stuff here
}


This seems like a logical way to go to newbies, but really it's creeping death.

Games (and really all programs) should strive to have everything treated the same way, with the same logic. Since the logic is all the same, all that changes is the data. So instead of hard-coding different areas, you can use the same code for every area and just change the data that's used.

In this instance, your data consists of 2 general parts:
1) the text you print to describe the scene
2) the options available to the player

You should store these parts seperately from the code, and just have your code access the appropriate data at the appropriate time.

For a very simplistic example (and you'll have to excuse the crudity here, as I only put about a minute of thought into this).

This is also really sloppy. You could clean this up by putting the classes in different headers and stuff:

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
enum Action
{
  act_none,  // not a valid action
  act_move, // move to a different location
  act_text  // print some new text on the screen
};

struct Option
{
  Option() : action(act_none) { }  // the default option has no action

  string display;
  Action action;

  // different data used depending on the type of action
    int act_int;
    string act_string;

  static Option Move(const string& display,int moveto)
  {
    Option r;
    r.display = display;
    r.action = act_move;
    r.act_int = moveto;
    return r;
  }

  static Option Text(const string& display,const string& text)
  {
    Option r;
    r.display = display;
    r.action = act_text;
    r.act_string = text;
    return r;
  }
};

struct Area
{
  string description;
  Option[4]  options;

  Area(const string& desc,const Option& o0,const Option& o1 = Option(),const Option& o2 = Option(),const Option& o3 = Option())
  {
    description = desc;
    options[0] = o0;
    options[1] = o1;
    options[2] = o2;
    options[3] = o3;
  }
};

//=================================
//  The areas.  Probably you should put these in a .txt file or something and load them.
// You generally don't want to store the game data in the program.
// But whatever, this is an example

enum
{
  area_beach = 0,
  area_forest
};


Areas theareas[] = {

// beach
Area("You are on the beach.  Check out the waves!",
  Option::Move("Go to the forest", area_forest)
  );

// forest
Area("You are in a forest.  So many trees!",
  Option::Move("Go to the beach", area_beach),
  Option::Text("Punch a tree","Ouch!  I think you broke your hand!")
  );


Your code would then all just keep track of which area you're in, present the options for that area, and perform the appropriate action based on the option the player selected.

All the code would be the same for every area.


Of course this all isn't very "simple". Choose-your-own-adventure games are actually one of the harder games for beginners to make. A simple vertical shooter / space invaders clone would be easier.


</my 4 cents>
Last edited on
Topic archived. No new replies allowed.