Text Adventure

Hey Guys, I'm developing a text adventure in C++! When I first started coding, I thought I would be coding video games like Battle Field or Counter Strike within two years. I didn't understand that coding was an entire new language with many different dialects and ways to say the same thing. I decided to aim my goals a little lower. My friend gave me the idea of creating a Text Adventure. For those of you who don't know what a text adventure is, it is a book that has multiple endings and you try to use reasoning and gut feelings to get a happy ending. I'm pretty sure I'm making my text adventure more complex than it has to be. Maybe it's my style, but for each branching decision, I find it harder to organize my program's different paths and it takes a long time for me to sift through all the coding and find what path leads where.

I will post my coding on a different post on this thread because it exceeds the maximum # of characters. LOL! If anyone has suggestions, I would appreciate them. Just remember to dumb them down a little, because I'm relatively inexperienced when it comes to coding. Also, my story isn't done yet, so if any of you are imaginative, I would like to hear ideas for the plot! Thanks a lot!

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
#include <iostream>
using namespace std;
#include <string>
#include <thread>
#include <chrono>


string answer, answer1, answer2, answer3, answer4, answer5, answer6, answer7, answer8, answer9, answer10;
int a, b;


int main()

{
	//part 1
	
	cout << "INSRUCTIONS: This is a text adventure. You will be forced to make decisions that will ultimately decide if you live or die. Some decisions require a 'yes' or a 'no,' while others require you to type in the correct number. That is all you need to know! "<<endl;
	  cin.get();
Beginning:
	system("CLS");
	 cout << "You're a secret agent working for the American Government. Your mission is to infiltrate a Russian prison and break out a fellow American who is being held hostage there. "<<endl;
	  cout << "The person you are breaking out is a white female. She is about 19 years old and is named Nicole. Break her out before the Russians are able to interrogate her successfully. "<<endl;
	   cout << "Your codename will be Boris. We've arranged a plane to take you there. You'll   ";
	    cout << "receive further orders once in Moscow."<<endl;
	     cout << "Do you accept your mission agent?"<<endl;
		  cin >> answer;

		//continues after yes
	    if (answer == "yes" || answer == "Yes")
	 {   cout << "Goodluck agent. ~END TRANSMISSION~"<<endl; }


		//continues after no
		else if (answer == "No" || answer == "no")
		{   
		   system("CLS");
			cout << "I am dissapointed in you..."<<endl;
		      std::this_thread::sleep_for(std::chrono::milliseconds(2000)) ;  //pauses for 2 seconds
		         system("CLS");
		           cout << "I must regretfully inform you that you will not be allowed to leave. You will now die."<<endl; 
		             std::this_thread::sleep_for(std::chrono::milliseconds(4000)) ;



		a = 1;
		b = 500;
		while (a < b)
	{ cout << "-  -    -      - -  -    -  - -   -     -       -   -    -   - -    -  -";
	a = a + 1; }
		system("CLS");
		cout << "YOU DIED";
		std::this_thread::sleep_for(std::chrono::milliseconds(4000)) ;
		system("CLS");
		cout << "Would you like to restart?"<<endl;
		cin >> answer1;

		if ( answer1 == "yes" || answer1 == "Yes")
		{ goto  Beginning; }
		
		else if (answer1 == "no" || answer1 == "No")
			{ return 0; }
		}

		else if (answer != "yes" && answer != "no")
			{ cout << "Did you read the instructions? Either you didn't read the instructions or your just plain stupid."<<endl;  //security protocol if someone doesnt answer yes or no
		     std::this_thread::sleep_for(std::chrono::milliseconds(4000)) ;                                                                                                   
		return 0; 

		}
		
		//Part 2: continues after you agree to the mission

	std::this_thread::sleep_for(std::chrono::milliseconds(2000)) ;
	system ("CLS");

	a = 1;
	b = 500;

	while (a < b)
	{ cout << "-  -    -      - -  -    -  - -   -     -       -   -    -   - -    -  -";
	a = a + 1; }

	system ("CLS");
	cout << "As you walk out of the Moscow International Airport, a dark black van with tinted windows pulls up. The van door slides open. ";
	cout << "A man wearing shades beckons you in. ``I am your supplier. Get in,'' he whispers. DO YOU TRUST HIM?"<<endl;
	cin >> answer2;

	if (answer2 == "yes")
	{ goto yes;  }

	if (answer2 == "no")
	{ system("CLS");
	cout << "The man waves frantically. ``Get in! There's not much time!'' SHOULD YOU ENTER?"<<endl; }
		cin >> answer3;
		if (answer3 == "yes")
		{ goto yes; }

		else if (answer3 == "no")  //if you don't get in van....
		{ system ("CLS");            
	cout << "``You are making big mistake!'' he shouts. The door slams shut and the van squeals away."<<endl;
	cout << "That guy was a weirdo, you think. You decide to head to a bus stop to make it to the prison. All of a sudden you feel something hard press against your back."<<endl;
	cout << "You turn around and there's a guy with a gun aimed at you. ``Do not make this any more difficult for yourself. I know you are an American agent. Do you know what ";
	cout << "the Russiam Government does to spies? It's not pretty,'' he laughs.             ~12 HOUR LATER~  You are tried in court and convicted guilty of being a spy. The punishment is torture until death. Dou you know what water boarding is?"<<endl;
	cout << "GAME OVER"<<endl;
	cin.get();

	a = 1;
	b = 500;

	while (a < b)
	{ cout << "-  -    -      - -  -    -  - -   -     -       -   -    -   - -    -  -";
	a = a + 1; }  
		system("CLS");
		cout << "Would you like to restart?"<<endl;
		cin >> answer4;

		if ( answer4 == "yes" || answer1 == "Yes")
		{ goto  Beginning; }
		
		else if (answer4 == "no" || answer1 == "No")
			{ return 0; }
	}

		else if (answer2 != "yes" && answer2 != "no")
			{ cout << "Did you read the instructions? Either you didn't read the instructions or your just plain stupid."<<endl;  //security protocol if someone doesnt answer yes or no
		        std::this_thread::sleep_for(std::chrono::milliseconds(4000)) ;                                                                                             
		                                                            goto Beginning ; }



		else if (answer3 != "yes" && answer3 != "no")
			{ cout << "Did you read the instructions? Either you didn't read the instructions or your just plain stupid."<<endl;  //security protocol if someone doesnt answer yes or no
		        std::this_thread::sleep_for(std::chrono::milliseconds(4000)) ;                                                                                                
		return 0; }





		//part 3

		yes:            //yes

	if (answer2 == "yes" || answer3 == "yes")
	{ system("CLS");
	cout << "You step into the van and it speeds off. The man takes off his shades. ``Are you Boris?'' he asks. The man has a rough voice and a heavy Russian accent as if he's ";
	cout << "spent a lot of time helping spies like you out in Russia. ``Da,'' you answer. ``I am Victor. You are being taken you to our secret facility under the American Embassy. I will provide weapons.''"<<endl;
	cout << "                            ~15 MINUTES LATER~"<<endl;
	  cin.get();
	    system("CLS");
	cout << "Once at the Embassy, you and Victor walk through the entrance. Victor walks over to the counter and shows them a card. The intern tells him to wait in room 333. Victor and you walk along a hallway with numbered doors on either side. An arm wraps around your neck."<<endl;
	cout << "''Hey guys!'' the man says enthusiastically. You instinctively reach around, grab his collar and slam him down hard. The man is probably still in his teens. He has an acne problem, and short, unkempt hair; with a butt chin and blue eyes. But overall he was guite handsome. " <<endl; 
	cout << " ''Ow.'' he whimpered. ''I thought you were someone else.'' he complained. You reach your hand out and he pulls himself up. You look him in the eye. '' I apologize.'' He turns the other direction and speed walks away. Victor is about to say something when his face tightens up and he falls down. "<<endl;
	
	cin.get();
		system("CLS");
	cout << "YOU HAVE A MOMENT TO REACT AND INSTANTLY TWO OPTIONS POP UP IN YOUR HEAD: One) DUCK INTO A DIFFERENT CORRIDOR AND RUSH TO THE FRONT DESK TO GET THE HOTEL SECURITY TO HELP. Two) GET BEHIND A GARBAGE CAN AND CHECK HIS BODY FOR WOUNDS. MAKE THE DECISION QUICKLY!"<<endl; 
	} 
	
	  cin >> answer5;
	
	


My coding exdeeds the maximum # of characters, so I will post the rest below...
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

if (answer5 == "One" || (answer5 == "one"))                 //this is if answer is One
  { cout << "You rush towards the front desk and tell the clerk what happened. Armed guards are instantly scrambled and you lead them towards the place Victor became unconsious and possibly dead."<<endl;
    cout << "Suddenly your legs go stiff and you begin to fall. Someone catches you, and yelling breaks out. But their voices are distant, hardly noticeble. A wave of peace comes over you, as if all the stress you ever felt is melting away." <<endl ;
	cout <<	"You suddenly don't care if you never wake up, If you never leave this peace. Your wish is granted and you never wake up. You were killed by a vicious toxin known as polonium that was inserted into your neck. The authorities never find who did it. "<<endl;
      cin.get();
	  std::this_thread::sleep_for(std::chrono::milliseconds(4000)) ;
	system("CLS");

		a = 1;
		b = 500;
		while (a < b)
	{ cout << "-  -    -      - -  -    -  - -   -     -       -   -    -   - -    -  -";
		a = a + 1; } 
		system("CLS");
		cout << "YOU DIED";
		  std::this_thread::sleep_for(std::chrono::milliseconds(4000)) ;
		system("CLS");
		cout << "Would you like to restart?"<<endl;
		cin >> answer1;

		if ( answer1 == "yes" || answer1 == "Yes")
		{ goto  Beginning; }
		
		else if (answer1 == "no" || answer1 == "No")
			{ return 0; }
  }


  else if (answer5 != "one" && answer5 != "two")
   {       system("CLS");  
	           cout << "Did you read the instructions? Either you didn't read the instructions or your just plain stupid."<<endl;  //security protocol if someone doesn't answer yes or no
		           std::this_thread::sleep_for(std::chrono::milliseconds(4000)) ;                                                                                                  
		                goto Beginning;
  }
	
	
  if (answer5 == "Two" || (answer5 == "two"))   //if answer5 is one
  { 
	  system("CLS");
	     cout << "You survive. To be continued!" <<endl;
		 
		 //For some reason I am forced to use two cins...
		 
		 cin.get();
			 cin.get();
  }
  




  




	
	return 0;  
	}
Maybe it's my style, but for each branching decision, I find it harder to organize my program's different paths and it takes a long time for me to sift through all the coding and find what path leads where.


Might I suggest you create a flow chart/pseudo code first?


As far as the code goes I would try to stay away from using goto and system.
Then I would suggest you break your code into subfunctions.
Sorry...I don't really understand what subfunctions or chart/pseudo are. I'm new to coding and don't have the lingo down yet.
That is very informative, and I'll reconsider what medium I use to code in the future. But I don't want this program to go to waste, and also...completing this will tell me that I have a basic understanding of the beginner stuff. So if there is anyone still viewing this thread, I would still like some constructive criticism, ideas on how to restructure my program, coding stuff, or ideas on the plot. Thanks!
Hello,

Unfortunately, if you're not careful, people might think you're a troll - just because you mentioned thinking you could write a triple-A title equivalent to Battle Field/Counter Strike - and because you're asking our suggestions on the plot of your text adventure.
In addition, your code is very hard to look at and understand.

I would suggest reading all the tutorials present on this website.
http://www.cplusplus.com/doc/tutorial/

You won't need to know everything to complete to this project, of course.
You have to realize that as you add more and more things to your game, it'll become harder and harder for you to make everything play nice with one-another. You can't hardcode every single possible story-arc into the source code, so what can you do? Try to think how other simple games might handle this. Here's a vague description of how I might do it:

1.) Write all the story text I need in a file of some sort.
2.) Write a class to handle the parsing of that file.
3.) Do things with the text (print it).
4.) Come up with a data-driven solution, and set up a main game loop.

The game shouldn't care what the contents of the game are. It's good practice to decouple things as much as possible, and only have your program know about other parts of itself when necessary.

Also, it's very odd to ask about story writing on a programming forum.
Last edited on
Xismn, I will take you up on your idea to use the tutorials on the website. However, I'm confused why people would think that I am a troll. When I started coding, I had never bothered to search how people make games such as Battle Field or Counter Strike. I thought someone coded Counter Strike by them self in a couple months. I didn't realize it truly was a new language. So, please do not confuse honesty with trolling. Just because I am on the internet, does not mean I am trying to waste your time and have no morals. I would not assume you to try to waste someone's time. Also, when I asked if anyone had any ideas for the plot, I didn't expect anyone to give me any. But if there was an imaginative person on this forum, they would have been welcome to post ideas.

If there are any other helpful suggestion, please comment.
Hi,

1
2
string answer, answer1, answer2, answer3, answer4, answer5, answer6, answer7, answer8, answer9, answer10;
int a, b;


I just wanted to say that an array would probably be better for this job here. Also, it'd be best to give the variables 'a' & 'b' a more descriptive name.

I'd also probably be best if you encapsulated this program in an OOP structure, and that would greatly ease adding new content with this, and overall increase the readability of your program.

---
I'm also confused why my post was reported earlier?
Thank you very much avilius, I will make those changes. I am also confused. I don't remember reporting you and I don't know why I would. Maybe my bro used my account or something. I don't how how to un-report you...but I'll try.
Topic archived. No new replies allowed.