Jailbreak: a simple text adventure in Unity

As part of an ongoing course I’m taking in Unity game development, I created a short text adventure called Jailbreak. You can play the game by clicking the picture below:

Jailbreak preview You can find the full code below:

Jailbreak (C#)

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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
 
public class TextController : MonoBehaviour {
 
	public Text text;
	private enum States {intro, cell, mirror, sheets_0, lock_0, cell_mirror, sheets_1, mirror_broken, lock_1, hallway, femdoor, storage, smokealarm, guardroom,
						hallway_1, hallway_lighter, femdoor_lighter, storage_lighter, guardroom_lighter, smokealarm_lighter, hallway_sprinkler, femdoor_sprinkler,
						storage_sprinkler, smokealarm_sprinkler, guardroom_sprinkler, hallway_sprinkler_1, hallway_key, femdoor_key, storage_key, smokealarm_key,
						guardroom_key, femhallway, firstcell, secondcell, thirdcell, femhallway_lily};
	private States myState;
 
	// Use this for initialization
	void Start () {
		myState = States.intro;
	}
 
	// Update is called once per frame
	void Update () {
		print (myState);
		if (myState == States.intro) {
			state_intro ();
		} else if (myState == States.cell) {
			state_cell ();
		} else if (myState == States.sheets_0) {
			state_sheets_0 ();
		} else if (myState == States.mirror) {
			state_mirror ();
		} else if (myState == States.lock_0) {
			state_lock_0 ();
		} else if (myState == States.cell_mirror) {
			state_cell_mirror ();
		} else if (myState == States.sheets_1) {
			state_sheets_1 ();
		} else if (myState == States.mirror_broken) {
			state_mirror_broken ();
		} else if (myState == States.lock_1) {
			state_lock_1 ();
		} else if (myState == States.hallway) {
			state_hallway ();
		} else if (myState == States.femdoor) {
			state_femdoor ();
		} else if (myState == States.storage) {
			state_storage ();
		} else if (myState == States.smokealarm) {
			state_smokealarm ();
		} else if (myState == States.guardroom) {
			state_guardroom ();
		} else if (myState == States.hallway_1) {
			state_hallway_1 ();
		} else if (myState == States.hallway_lighter) {
				state_hallway_lighter ();
		} else if (myState == States.femdoor_lighter) {
			state_femdoor_lighter ();
		} else if (myState == States.storage_lighter) {
			state_storage_lighter ();
		} else if (myState == States.smokealarm_lighter) {
			state_smokealarm_lighter ();
		} else if (myState == States.guardroom_lighter) {
			state_guardroom_lighter ();
		} else if (myState == States.hallway_sprinkler) {
			state_hallway_sprinkler ();
		} else if (myState == States.hallway_sprinkler_1) {
			state_hallway_sprinkler_1 ();
		} 	else if (myState == States.femdoor_sprinkler) {
			state_femdoor_sprinkler ();
		} else if (myState == States.storage_sprinkler) {
			state_storage_sprinkler ();
		} else if (myState == States.smokealarm_sprinkler) {
			state_smokealarm_sprinkler ();
		} else if (myState == States.guardroom_sprinkler) {
			state_guardroom_sprinkler ();
		} else if (myState == States.hallway_key) {
			state_hallway_key ();
		} 	else if (myState == States.femdoor_key) {
			state_femdoor_key ();
		} else if (myState == States.storage_key) {
			state_storage_key ();
		} else if (myState == States.smokealarm_key) {
			state_smokealarm_key ();
		} else if (myState == States.guardroom_key) {
			state_guardroom_key ();
		} else if (myState == States.femhallway) {
			state_femhallway ();
		} else if (myState == States.firstcell) {
			state_firstcell ();
		} else if (myState == States.secondcell) {
			state_secondcell ();
		} else if (myState == States.thirdcell) {
			state_thirdcell ();
		} else if (myState == States.femhallway_lily) {
			state_femhallway_lily ();
		}
	}
 
	#region state handler methods
 
	void state_intro () {
		text.text = "\n\nYou wake up from the sound of something hitting metal. It might as well be hitting " +
					"you straight on the skull. You have a terrible headache and an even worse feeling in " +
					"your stomach. You look up to see the bulge in the top bunk, revealing where your " +
					"gorilla of a cell mate is currently sleeping off his hangover. Booze is not hard to " +
					"find in here, provided you have the right friends. Not exactly your specialty, the friend " +
					"department. Most certainly not in here. But then you remember the one friend you do have. " +
					"You need to get out of here and save her. She hasn't got much time left. You smash your " +
					"fist against the wall in anger. Your knuckles add to the symphony of pain, but at least " +
					"your head doesn't feel as bad as before. You grunt and get up, just as the guard finishes " +
					"his morning rounds.\n\n\nPress space to continue.";
		if (Input.GetKeyDown(KeyCode.Space)){
			myState = States.cell;
		}
	}
 
	void state_cell (){
		text.text = "\n\nYou pace through your cell.\n\n\nPress 'S' to view sheets." +
				"\nPress 'M' to view mirror." +
				"\nPress 'L' to view lock.";
		if (Input.GetKeyDown(KeyCode.S)){
			myState = States.sheets_0;
		} else if (Input.GetKeyDown(KeyCode.M)){
			myState = States.mirror;
		} else if (Input.GetKeyDown(KeyCode.L)){
			myState = States.lock_0;
		}
	}
 
	void state_sheets_0 (){
		text.text = "\n\nYou look at the sheets. You cannot believe you sleep in these things. They haven't been changed in ages. " +
					"Yet another example of the pleasures of prison life.\n\nPress 'R' to return to roaming your cell.";
		if (Input.GetKeyDown(KeyCode.R)){
			myState = States.cell;
		}
	}
 
	void state_mirror (){
		text.text = "\n\nYou look at your reflection in the mirror. It has seen better days. The friendly neighbourhood gorilla smashed " +
					"the lower right corner to pieces. \n\nPress 'P' to pry loose a shard of the mirror.\nPress 'R' to return to roaming your cell.";
		if (Input.GetKeyDown(KeyCode.R)){
			myState = States.cell;
		} else if (Input.GetKeyDown(KeyCode.P)){
			myState = States.cell_mirror;
		}
	}
 
	void state_lock_0 (){
		text.text = "\n\nYou try the cell door. Unsurprisingly, it's closed. The lock is operated through a keypad. " +
					"You have no idea what the combination is. You wish you could somehow see where the dirty " +
					"fingerprints on the outer keypad were, maybe that would help. \n\nPress 'R' to return to roaming your cell.";
		if (Input.GetKeyDown(KeyCode.R)){
			myState = States.cell;
		}
	}
 
	void state_cell_mirror (){
		text.text = "\n\nYou pace through your cell with the mirror shard in your hand.\n\n\nPress 'S' to view sheets." +
					"\nPress 'M' to view mirror." +
					"\nPress 'L' to view lock.";
		if (Input.GetKeyDown(KeyCode.S)){
			myState = States.sheets_1;
		} else if (Input.GetKeyDown(KeyCode.M)){
			myState = States.mirror_broken;
		} else if (Input.GetKeyDown(KeyCode.L)){
			myState = States.lock_1;
		}
	}
 
	void state_sheets_1 (){
		text.text = "\n\nYou look at the sheets. You cannot believe you sleep in these things. They haven't been changed in ages. " +
			"Yet another example of the pleasures of prison life.\n\nPress 'R' to return to roaming your cell.";
		if (Input.GetKeyDown(KeyCode.R)){
			myState = States.cell_mirror;
		}
	}
 
	void state_mirror_broken (){
		text.text = "\n\nYou look at your reflection in the mirror. It has seen better days. A shard in the lower right is missing. " +
					"\n\nPress 'R' to return to roaming your cell.";
		if (Input.GetKeyDown(KeyCode.R)){
			myState = States.cell_mirror;
		}
 
	}
 
	void state_lock_1 (){
		text.text = "\n\nYou slide the mirror shard under the door and after some adjustments, you can see the keypad. The two " +
					"bottom rows are clearly more worn-out than the others. Surely these guards couldn't be this sloppy? " +
					"\n\nPress 'R' to return to roaming your cell.\nPress 'C' to enter the combination '9876' on the keypad.";
		if (Input.GetKeyDown(KeyCode.R)){
			myState = States.cell_mirror;
		} else if (Input.GetKeyDown(KeyCode.C)){
			myState = States.hallway;
		}
	}
 
	void state_hallway (){
		text.text = "\n\nThe keypad gives a short buzz and the door unlocks. You slip out before your cellmate wakes up and find yourself in a dimly light corridor." +
					"At the end of the hallway you can see the door that leads to the female wing, where Lily is being held. There's a small storage room a few feet " +
					"to your right. Several sprinklers and two smoke alarms are attached to the corridor ceiling. You can hear the faint noise from a TV set coming from the guard booth." +
					"\n\nPress 'F' to try the door to the female wing of the prison." +
					"\nPress 'S' to go into the storage room. \nPress 'A' to inspect the smoke alarm. \n Press 'G' to sneak up to the guard room.";
		if (Input.GetKeyDown(KeyCode.F)){
			myState = States.femdoor;
		} else if (Input.GetKeyDown(KeyCode.S)){
			myState = States.storage;
		} else if (Input.GetKeyDown(KeyCode.A)){
			myState = States.smokealarm;
		} else if (Input.GetKeyDown(KeyCode.G)){
			myState = States.guardroom;
		}
	}
 
	void state_femdoor (){
		text.text = "\n\nThe door to the female prison wing is made from half a foot of solid steel. It doesn't have a keypad, but instead sports an enormous keyhole." +
					"\n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_1;
		}
 
	}
 
	void state_storage (){
			text.text = "\n\nThere's a storage rack with cardboard boxes in the room. In the corner you can see a bucket and some mops, as well as several bottles of detergent " +
				"Next to one of the cardboard boxes you see half a pack of cigarettes and a lighter. \n\nPress 'H' to return to the hallway. \nPress 'L' to take the lighter.";
			if (Input.GetKeyDown(KeyCode.H)){
				myState = States.hallway_1;
			} else if (Input.GetKeyDown(KeyCode.L)){
				myState = States.hallway_lighter;
			}
		}
 
	void state_smokealarm (){
			text.text = "\n\nThe smoke alarm is seems pretty old, but the blinking red light tells you that it still works." +
				"\n\nPress 'H' to return to the hallway.";
			if (Input.GetKeyDown(KeyCode.H)){
				myState = States.hallway_1;
			}
 
		}
 
	void state_guardroom (){
			text.text = "\n\nThe guard room's door is slightly ajar. You peek through and see the guard watching 'Whose line is it anyway?' on a portable TV set. He's laughing loudly." +
						"There's a bunch of keys on a wall-mounted rack. The guard shifts in his chair and you quickly hide behind the door. \n\nPress 'H' to return to the hallway.";
			if (Input.GetKeyDown(KeyCode.H)){
				myState = States.hallway_1;
			}
 
		}	
 
	void state_hallway_1 (){
		text.text = "\n\nAt the end of the hallway you can see the door that leads to the female wing, where Lily is being held. There's a small storage room a few feet " +
					"to your right. Several sprinklers and two smoke alarms are attached to the corridor ceiling. You can hear the faint noise from a TV set coming from the guard booth." +
					"\n\nPress 'F' to try the door to the female wing of the prison." +
					"\nPress 'S' to go into the storage room. \nPress 'A' to inspect the smoke alarm. \n Press 'G' to sneak up to the guard room.";
		if (Input.GetKeyDown(KeyCode.F)){
			myState = States.femdoor;
		} else if (Input.GetKeyDown(KeyCode.S)){
			myState = States.storage;
		} else if (Input.GetKeyDown(KeyCode.A)){
			myState = States.smokealarm;
		} else if (Input.GetKeyDown(KeyCode.G)){
			myState = States.guardroom;
		}
	}
 
	void state_hallway_lighter (){
		text.text = "\n\nAt the end of the hallway you can see the door that leads to the female wing, where Lily is being held. There's a small storage room a few feet " +
				"to your right. Several sprinklers and two smoke alarms are attached to the corridor ceiling. You can hear the faint noise from a TV set coming from the guard booth." +
				"\n\nPress 'F' to try the door to the female wing of the prison." +
				"\nPress 'S' to go into the storage room. \nPress 'A' to inspect the smoke alarm. \n Press 'G' to sneak up to the guard room.";
		if (Input.GetKeyDown(KeyCode.F)){
			myState = States.femdoor_lighter;
		} else if (Input.GetKeyDown(KeyCode.S)){
			myState = States.storage_lighter;
		} else if (Input.GetKeyDown(KeyCode.A)){
			myState = States.smokealarm_lighter;
		} else if (Input.GetKeyDown(KeyCode.G)){
			myState = States.guardroom_lighter;
		}
	}
 
	void state_femdoor_lighter (){
		text.text = "\n\nThe door to the female prison wing is made from half a foot of solid steel. It doesn't look like it would melt even if you used up all the lighter fluid. " +
					"It doesn't have a keypad, but instead sports an enormous keyhole." +
					"\n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_lighter;
		}
 
	}
 
	void state_guardroom_lighter (){
		text.text = "\n\nThe guard room's door is slightly ajar. You peek through and see the guard watching 'Whose line is it anyway?' on a portable TV set. He's laughing loudly." +
				"There's a bunch of keys on a wall-mounted rack. You briefly contemplate to set the nearby paper bin on fire, but when the guard shifts in his chair you quickly hide " +
				"behind the door. \n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_lighter;
		}
 
	}	
 
	void state_storage_lighter (){
		text.text = "\n\nThere's a storage rack with cardboard boxes in the room. In the corner you can see a bucket and some mops, as well as several bottles of detergent " +
			"Next to one of the cardboard boxes you see half a pack of cigarettes. You took the lighter earlier. \n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_lighter;
		}
	}
 
	void state_smokealarm_lighter (){
		text.text = "\n\nThe smoke alarm is seems pretty old, but the blinking red light tells you that it still works." +
			"\n\nPress 'L' to hold the lighter under the smoke alarm. \nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_1;
		} else if (Input.GetKeyDown(KeyCode.L)){
			myState = States.hallway_sprinkler;
		}
	}
 
	void state_hallway_sprinkler (){
		text.text = "\n\nSprinklers suddenly erupt and you hear the guard rushing out of his room while you quickly hide in the storage room. " +
					"The guard runs by while yelling something in his walkie-talkie." +
					"\n\nPress 'H' to return to the hallway after the guard has left.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_sprinkler_1;
		}
	}
 
	void state_hallway_sprinkler_1 (){
		text.text = "\n\nSprinklers are releasing large amounts of water throughout the hallway. You can just make out the door to the female prison wing at the end of the hallway. " +
					"The storage room is to your right. \n\nPress 'F' to try the door to the female wing of the prison." +
					"\nPress 'S' to go into the storage room. \nPress 'A' to inspect the smoke alarm. \n Press 'G' to sneak up to the guard room.";
		if (Input.GetKeyDown(KeyCode.F)){
			myState = States.femdoor_sprinkler;
		} else if (Input.GetKeyDown(KeyCode.S)){
			myState = States.storage_sprinkler;
		} else if (Input.GetKeyDown(KeyCode.A)){
			myState = States.smokealarm_sprinkler;
		} else if (Input.GetKeyDown(KeyCode.G)){
			myState = States.guardroom_sprinkler;
		}
	}
 
	void state_femdoor_sprinkler (){
		text.text = "\n\nThe door to the female prison wing is made from half a foot of solid steel. It's getting rather wet, but it doesn't look like it would disintegrate from rust " +
					" any time soon. It doesn't have a keypad, but instead sports an enormous keyhole." +
					"\n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_sprinkler;
		}
 
	}
 
	void state_guardroom_sprinkler (){
		text.text = "\n\nThe guard room's door is wide open now. The TV is still on, but the guard is nowhere to be seen. He took several keys from the rack, but there's a couple of keys left. " +
					"\n\nPress 'T' to take the large key from the rack. \nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_sprinkler;
		} else if (Input.GetKeyDown(KeyCode.T)){
			myState = States.hallway_key;
		} 
 
	}	
 
	void state_storage_sprinkler (){
		text.text = "\n\nThe cardboard boxes on the storage rack are becoming soggy. The bucket is slowly filling with water. There's a faint hint of cleaning detergent in the air. " +
					"\n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_sprinkler;
		}
	}
 
	void state_smokealarm_sprinkler (){
		text.text = "\n\nThe majority of the smoke alarm is charred from your lighter. The red light is still blinking. " +
					"\n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_sprinkler;
		}
	}
 
	void state_hallway_key (){
		text.text = "\n\nSprinklers are releasing large amounts of water throughout the hallway. You can just make out the door to the female prison wing at the end of the hallway. " +
					"The storage room is to your right. \n\nPress 'F' to try the door to the female wing of the prison." +
					"\nPress 'S' to go into the storage room. \nPress 'A' to inspect the smoke alarm. \n Press 'G' to sneak up to the guard room.";
		if (Input.GetKeyDown(KeyCode.F)){
			myState = States.femdoor_key;
		} else if (Input.GetKeyDown(KeyCode.S)){
			myState = States.storage_key;
		} else if (Input.GetKeyDown(KeyCode.A)){
			myState = States.smokealarm_key;
		} else if (Input.GetKeyDown(KeyCode.G)){
			myState = States.guardroom_key;
		}
	}
 
	void state_femdoor_key (){
		text.text = "\n\nThe door to the female prison wing is made from half a foot of solid steel. It's getting rather wet, but it doesn't look like it would disintegrate from rust " +
					" any time soon. It doesn't have a keypad, but instead sports an enormous keyhole." +
					"\n\nPress 'U' to unlock the door. \nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_key;
		} else if (Input.GetKeyDown(KeyCode.U)){
			myState = States.femhallway;
		} 
 
	}
 
	void state_guardroom_key (){
		text.text = "\n\nThe guard room's door is wide open now. The TV is still on, but the guard is nowhere to be seen. He took several keys from the rack, but there's a couple of keys left. " +
					"You have already taken the large key from the rack. \n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_key;
		} 
 
	}	
 
	void state_storage_key (){
		text.text = "\n\nThe cardboard boxes on the storage rack are becoming soggy. The bucket is slowly filling with water. There's a faint hint of cleaning detergent in the air. " +
					"\n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_key;
		}
	}
 
	void state_smokealarm_key (){
		text.text = "\n\nThe majority of the smoke alarm is charred from your lighter. The red light is still blinking. " +
					"\n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.hallway_key;
		}
	}
 
	void state_femhallway (){
		text.text = "\n\nYou find yourself in the female prison wing. The sprinklers have been turned on here as well. There are several occupied cells. " +
					"\n\nPress 'F' to look through the first cell door." +
					"\nPress 'S' to look through the second cell door. \nPress 'T' to look through the first cell door.";
		if (Input.GetKeyDown(KeyCode.F)){
			myState = States.firstcell;
		} else if (Input.GetKeyDown(KeyCode.S)){
			myState = States.secondcell;
		} else if (Input.GetKeyDown(KeyCode.T)){
			myState = States.thirdcell;
		}
	}
 
	void state_firstcell (){
		text.text = "\n\nA woman is standing on the other side of the door. She's trying to see what is going on. As soon as she spots you, she starts " +
					"banging on the door and shouting at you to open her cell" +
					"\n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.femhallway;
		}
	}
 
	void state_secondcell (){
		text.text = "\n\nThe cell is empty" +
					"\n\nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.femhallway;
		}
	}
 
	void state_thirdcell (){
		text.text = "\n\nAt long last, you find Lily. She breaks out into a devilish little grin as she sees you. 'About time!' she laughs." +
					"\n\nPress 'C' to try the same combination on the keypad. \nPress 'H' to return to the hallway.";
		if (Input.GetKeyDown(KeyCode.H)){
			myState = States.femhallway;
		} else if (Input.GetKeyDown(KeyCode.C)){
			myState = States.femhallway_lily;
		}
	}
 
	void state_femhallway_lily (){
		text.text = "\n\nLily takes you by the hand and pulls you through another corridor into a maintenance room. You spot a sewage duct and reluctantly make " +
					" your way out to the main sewers. After wandering through the sewer system for what feels like at least a day, you suddenly spot light in the distance." +
					"\n\nFreedom awaits. \n\n\n\n\nPress space to play again.";
		if (Input.GetKeyDown(KeyCode.Space)){
			myState = States.intro;
		}
	}
 
	#endregion
}

[collapse]

As always, any tips or comments are greatly appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *