Text adventure, having two separate story lines but combing them

So I was assigned to create a study tool for world history, so I went with a text based adventure game. At this point I want the player to decide the government that there civ based on their beliefs. so I did not show what story line they are following yet. However just in case they did not understand a decision or did not make what they wanted to make I am giving way to jump into other story lines. How do I do this? I though I could do it with void seconds(){} or int seconds() {} but I use return in my code so void did not work and int would not work either. here is the code:

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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include <iostream>
#include <string> 
#include <Windows.h> 
#include <stdlib.h>

using namespace std;

bool gameRunning = true;
int rand1to100 = rand() % 100 + 1;

void Totalotarian()
{

}

int main()
{
	while (gameRunning == true)
	{
		system("Color 0a");
		cout << " !*PRE - ALPHA EXPECT SPELLING ERRORS AND GLITCHES*! Welcome to World History \n adventures! To play press the \" p \" and \"enter\" . To quit at any time press \" esc \". \n Please enjoy the adventure! Lead writer: Locke Thornburge, \n Lead Programmer Matthew Byrd" << endl;
		string startD;
		cin >> startD;
		if (startD == "p")
		{
			cout << "You want to start your civilization. You come across a river vally. \n What do you do? (s = settle, l = leave)" << endl;
			string secondD;
			cin >> secondD;
			if (secondD == "s")
			{
				cout << "you settle a wonderous civilization! However it appears to be missing \n something, what? (Hint: Mr. Barhams website. Alphabetical order \n (!*ALPHA*! the answer is \"TEMP\")" << endl;

				string thirdD;
				cin.ignore();
				getline(cin, thirdD);
				if (thirdD == "TEMP")
				{
					cout << "Your civilization's culture is booming! Insert a random number to have a \n event occur!" << endl;
					string fourthD;
					cin >> fourthD;

					if (fourthD == "1")
					{
						cout << "Your civilization devlops a wonder of the world! Your citizens rejoice! Press \"c\" to continue!" << endl;
						string decisionA1; //Start of culture campaign 
						cin >> decisionA1;

						if (decisionA1 == "c")
						{
							cout << "welcome to a new era! Your civ gains writing, sailing, calendar, trapping, the wheel, masonry, and bronze working. What do you want to achieve with these technologys? (p = pyrimids, g = great wall, s = statues, " << endl;

						}

						else
						{
							cout << "u wot m8?" << endl;
							Sleep(2000);
							return 0;
						}
					}

					if (fourthD == "420")
					{
						cout << "You disoverd hemp! However you pepole died prior to this." << endl;
					}



					else
					{
						cout << "Your civilizaion discovers gold mining! Your citizens suggest to use it for holy structures, however you could use this to trade with neighboring civilizations. What do you do? (r = holy structures, t = Trade with neighbors)" << endl;
						string decisionB1;
						cin >> decisionB1;
						if (decisionB1 == "r")
						{
							cout << "You build great structures however enslave your pepole to acheive this. press \"c\" to continue" << endl;
							string continuationB1;
							cin >> continuationB1;
							if (continuationB1 == "c")
							{

							}

							else
							{
								cout << "u wot m8?" << endl;
								Sleep(2000);
								return 0;
							}

						}

						if (decisionB1 == "t")
						{
							cout << "You trade away your gold for goods and now have the option to keep these resources for personle use or provide them to your pepole. (k = Keep, p = Give to pepole)" << endl;
							string decisionB2;
							cin >> decisionB2;
							if (decisionB2 == "k")
							{
								cout << "You civilization grows in goverment power. You can either establish a military, or establishment of a religon promoting government. (\"m\" = military, \"r\" = religon" << endl;
								string TotalotarianD; // start of Totalotarian campaign
								cin >> TotalotarianD;

								if (TotalotarianD == "m")
								{

									
									{
									cout << "You establishment of a military ensures protection of your civilization for decades to come. Welcome to a new era. Your civ gains writing, sailing, calendar, trapping, the wheel, masonry, and bronze working. What do you want to achieve with these technologys? Establish a new city (c)" << endl;
									string totalotarianD2;
									cin >> totalotarianD2;
									if (totalotarianD2 == "c")
									{
										string cityName;
										cout << "What would you like to name your city?" << endl;
										cin.ignore();
										getline(cin, cityName);
										cout << cityName << " has been established" << endl;
										Sleep(2000);
										string  cityDecision;
										cout << "How much protection do you provide in the city? (No wrong answer) " << endl;
										cin.ignore();
										getline(cin, cityDecision);
										cout << cityDecision << " applied to " << cityName << endl;
										Sleep(2000);
										string gameChangeT;
										cout << "You meet a new starter - up civilization, what do you do? Attack or leave (a for attack, \"l\" for leave" << endl;
										cin >> gameChangeT;

										if (gameChangeT == "l")
										{

										}

										if (gameChangeT == "a")
										{
											cout << "Your civilization attacks" << endl;
											if (rand1to100 <= 90)
											{
												rand1to100 = rand() % 100 + 1;
												cout << "Your civilization was sucsesfull the starter up fails. What would you like to ";
												Sleep(2000);
												cout << "WIP" << endl;
												Sleep(2000);
												return 0;
											}

											if (rand1to100 >= 10)
											{
												rand1to100 = rand() % 100 + 1;
												cout << "Your civilization failed, you lose";
												Sleep(2000);


											}
											else
											{
												cout << "your civilization !*TEMP*! misses" << endl;
											}
										}
										
										}

										}
									}
								}

								if (decisionB2 == "p")
								{
									cout << "By giving to the pepole your civilization has established trust in the government and gained more workers. Welcome to a new era. Your civ gains writing, sailing, calendar, trapping, the wheel, masonry, and bronze working. What do you want to achieve with these technologys? Esablish a theatre (t) Eastablish a early form of democracy (d)" << endl;
									string DemocraticD1; //start of democratic campaign
									cin >> DemocraticD1;

									if (DemocraticD1 == "t")
									{
										cout << "Your cuture provides happiness to all who surround it. There is a period of peace and prosparity. The lack of government causes citizens to worry, trade routes are begging to intercept your city and your economy is growing. However without a government run protection service, the crime is starting to increase. You have two options, either form a millitary or start democratic form of government. What do you do? (\"d\" = democratic, \"m\" = millitary" << endl;
										string DemocraticD2;
										cin >> DemocraticD2;

										if (DemocraticD2 == "m")
										{

										}

										if (DemocraticD2 == "d")
										{

										}

										
										
									}

									if (DemocraticD1 == "d")
									{

									}
								}
							}
						}
					}
				}

				if (secondD == "l")
				{
					cout << "you die of dehydration idiot" << endl;
				}
			}
		}
	}
closed account (2EwbqMoL)
I think what you need to do is drop the style of coding and do this in an object oriented fashion with classes.

if you write out all your civilization data in classes, then have class functions to manipulate and show that data, you can easily create several concurrent storyline classes/civilizations that can be called up with a mere function call.

they can even be as complete as the player controlled one, or ALL controlled by the player, you or AI. its up to how complex you want the code to be...

with OO classes you could have civil1.Civilization and civil2.Civilization...
civil1.foodStuffs civil2.foodStuffs...

civil1.Government, civil2.government...

and each could have input and output functions -- they can have the full functionality of Main, but literally be self containing multi-variables, using hte functionality to express themselves -- hence OBJECTS.

I'm writing a text game, and I have classes for items, inventory.. the player character themselves... monsters... even rooms!!!...

the whole game is actually defined in its objects!all I write in the main.cpp is the storyline, basic calls to objects etc. every aspect of my game, from the rooms to the variables (in yours the amount of food, choices etc...) is held in the classes, defined using functions therein, and only called up from main(). a whole room, and the items in it, are defined outside by the objects.h header I have declaring all my objects -- which ultimately form the core engine...

if I wanted to, I could write two concurrent maps with my room functions... simply by creating a separate set of members inaccessible to the player character, and the events of a storyline in THAT map could easily be called up by saying... Map2Room1.displayroom(); if I wanted (thats not a real function in my game but...)

there could be a whole set of room,a second hero...

that example code could say "A girl stands facing three lions fighting amongst each other. she carries a sword but does not appear to have the strength to fight all three! she notices a rock at her feet and what looks to be a lever at the end of the room... Thank god your in a different situation and dont have to solve her puzzle!"

in your game, you could have classes establishing what a civilization is, what your storyline is built up on (the core data), and have members representing both the players current realtime game world, and separate game worlds NOT controlled by the player (or even a combination thereof!)

this would be because the players world and the one you compare it to are built of the same data and functions... so the same functions you call up the player world with will be able to call up the non player comparison.

you wouldnt have the nasty nested ifs... it would be dynamic, readible, and controllable -- even memory handling would be easier (rid yourself of unneeded variables)...


Im not really sure what your asking, and IM not a good teacher... but I know making this object oriented will really help what your after...

going at this function by function like its a C program is going to be very terribly difficult and not dynamic at all...
closed account (2EwbqMoL)
this is REALLY messy and dependent on if statements rather than functions -- so at least consider what im saying...

unless of course you actually have the second story written and established but just dont have a way of showing two outputs at once?

it seemed to me you didnt even HAVE a second function showing anything related to other possibilities.

youd have to create the comparison world before loading it up for the player to see... and like I said, itd be MUCH easier doing that object oriented, because then every game object is an object, and you can create several realms at once with members you could create an instance of dictatorship, democracy, oligarchy, communism, capitalism, etc...

you could make all those worlds and possibilities much more easily, because there wouldnt be nested ifs -- it would be variables set in classes like Class Government{} and Class Resources{}... each member would have a set of the same variables, and functions related to those variables that can be called in outside code like main() or seconds(). CapitalWorld.Civilization could be an object, as well as PlayerWorld and CommunWorld.

each could have display and modification functions. CommunWorld.setMoney(99000), CapitalWorld.setMoney(1000000000); could have like... CommunWorld.DisplayWorld();, capitalWorld.DisplayWorld();...


if thats what your after.. I hope I helped...

I really think its the design aspect personally, but I dont really understand 100%
Those two options are good but I am afraid that they will take me personally to long to reprogram into that form, I would rather make a decision based adventure where only one path leads to the end and the decisions are based on how history actually happened.
Last edited on
closed account (2EwbqMoL)
well, how much have you got done so far? I dont really know what else to reccomend? You can still do things in a similar fashion to how I mentioned -- I was just saying the flexibility is there with that design, how you choose to manipulate it is up to you.

if you'd like me to take a look at your code you can pm me and I'll send you my email address or something, though I can't promise too much as Im not super experienced...

I'm just not sure what you mean by jump into other storylines either... are these storylines set in stone? from what I see, I only see a player story that the player is currently in... I dont see this second storyline your referencing or waht you mean by it...

are you saying that you want an alternative outcome based on what would have happened had the player made a different choice, a different society/continent? if it's set in stone, you could just assign string variables that state what would have happened... although classes STILL make this easier, because all the choices/outcomes would be set up based on the data in the classes (which is why its simpler and more flexible...)

like I said, if you'd like I can *try* to look at what you've got and help out if you want to email me... I could possibly share some of the code Im working on in my text adventure too so you can see an example... its too long to post here though...
Okay here is my code. The problem with this is that this is due next Monday. assigned last Monday. This was meant as a review project for students to teach the class, in which most people has chosen to do a top 10 list going in detail. Me and my colleague decided that would be a little less challenging then we would prefer. :

 
http://1drv.ms/1Jjraqs 

Last edited on
Topic archived. No new replies allowed.