Welcome, guest | Sign In | My Account | Store | Cart

for beginners.

Python, 519 lines
  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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#droids.py
import time
import random
from random import randint

print('\n' * 100)
print('\n\n[-Droids : by jay : type help-]')
print('\n\n\n------------------------')
print('        DROIDS')
print('------------------------')
print('\n10.03.2245 : cytek inc.')
time.sleep(1)
print('\nCTRL866 Re-Boot Sequence....')
time.sleep(1)
print('\nInitalizing Control Droid 866....')
time.sleep(1)
print('....')
time.sleep(1)
print('....')
time.sleep(1)
print('Laser offline...')
time.sleep(1)
print('Motion Tracker offline...')
time.sleep(1)
print('\nService Port avaliable...')
time.sleep(1)
print('....')
time.sleep(1)
print('....')
print('\nControl Droid Active.')
time.sleep(1)
print('''\n\nYou are the 866 Control Droid aboard 
the Droid Shuttle 'KERNEL'. Enemy droids have boarded
and have taken over flight path. You are damaged & have been 
re-initialized but your laser and motion tracker are offline.''')

def start(inventory):
	print('\n----------')
	print('\nDroid mobile..')
	time.sleep(1)
	print('....')
	time.sleep(1)
	print('\n[-MAIN ELEVATOR-]')
	print('\n1.) deck 1 - Security')
	print('2.) deck 2 - Maintenance')
	print('3.) deck 3 - Cargo Hold - Airlock')
	print('4.) deck 4 - Droid Hangar')
	print('5.) deck 5 - Shuttle Control')
	print('6.) deck 6 - Observation\n')
	
	cmdlist = ['1', '2', '3', '4', '5', '6',]
	cmd = getcmd(cmdlist)
	
	if cmd == '1':
		security(inventory)
	elif cmd == '2':
		if 'droid hack' in inventory:
			print('\n- DECK 2 - MAINTENANCE LOCKED -')
			time.sleep(2)
			start(inventory)
		else:
			maintenance(inventory)
	elif cmd == '3':
		cargo_hold(inventory)
	elif cmd == '4':
		if 'laser' in inventory:
			print('\n- DECK 4 - DROID HANGAR LOCKED -')
			time.sleep(2)
			start(inventory)
		else:
			droid_hangar(inventory)
	elif cmd == '5':
		shuttle_control(inventory)
	elif cmd == '6':
		if 'motion tracker' in inventory:
			print('\n- DECK 6 - OBSERVATION LOCKED -')
			time.sleep(2)
			start(inventory)
		else:
			observation(inventory)
		
def maintenance(inventory):
	print('\n----------')
	print('\nDroid mobile..')
	time.sleep(1)
	print('....')
	time.sleep(1)
	print('''\nThis is the maintenance deck and it appears deserted. 
You can see a terminated crew droid, it has sustained
severe laser fire.''')
	print('\n[-MAINTENANCE-]\n')
	print('1.) 716 Crew Droid')
	print('2.) Return to Main Elevator\n')
	
	cmdlist = ['1', '2']
	cmd = getcmd(cmdlist)
	if cmd == '1':
		crew_droid(inventory)
	elif cmd == '2':
		start(inventory)
		
def crew_droid(inventory, items=['droid hack']):
	print('\n----------')
	print('''\n716 has a droid hack program and it's connection
outlet is still intact. You can connect to this droid with service
port and download the program.''')
	if len(items) > 0:
		for item in items:
			print('\n--> %s' % (item))
			print('\n\n1.) Exit.')
	cmdlist = ['service port', '1']
	cmd = getcmd(cmdlist)
	if cmd == 'service port':
			inventory.append('droid hack')
			items = ['droid hack']
			print('\nservice port connected.')
			time.sleep(1)
			print('accessing file..')
			time.sleep(1)
			print('downloading..')
			time.sleep(1)
			print('....')
			time.sleep(1)
			print('\ndownload complete.')
			print('\nYou have the droid hack program and return')
			print('to the Main Elevator.')
			time.sleep(2)
			start(inventory)
	elif cmd == '1':
			maintenance(inventory)
	else:
		print('\n error. invalid command-')
	
def cargo_hold(inventory):
	print('\n----------')
	print('\nDroid mobile..')
	time.sleep(1)
	print('....')
	time.sleep(1)
	print('''\nYou enter the Cargo Hold, two Enemy Combat droids
unload a barrage of laser fire at you. Their fire is very accurate
and you take a direct hit in your main CPU.''')
	print('\n[-CARGO HOLD - AIRLOCK-]')
	print('....')
	time.sleep(1)
	print('....')
	time.sleep(1)
	print('\nshutdown imminent...')
	time.sleep(1)
	print('CTRL866 offline.')
	time.sleep(1)
	print('Droid terminated.')
	print('\nGAME OVER\n')
	exit(0)
	
def droid_hangar(inventory):
	print('\n----------')
	print('\nDroid mobile..')
	time.sleep(1)
	print('....')
	time.sleep(1)
	print('''\nThe Droid Hangar is filled with debri. There
is laser scoring everywhere and all droids are terminated.
In the corner there is one inactive repair droid still in his security
cylinder. You can initialise the droid to repair your laser but you will 
require a 3 digit access code.\n''')
	print('[-DROID HANGAR-]')
	print('\n1.) Repair Droid 3 digit code')
	print('2.) Return to Main Elevator')
	
	cmdlist = ['1', '2']
	cmd = getcmd(cmdlist)
	
	if cmd == '1':
		access_code(inventory)
	elif cmd == '2':
		start(inventory)
		
def access_code(inventory):
	code = '%d%d%d' % (randint(0,9), randint(0,9), randint(0,9))
	guess = input('\n[KEYPAD]> ')
	guesses = 0
	
	while guess != code and guess != 'yu8xxj3' and guesses <4:
		print('\n* ACCESS - DENIED *')
		guesses += 1
		guess = input('\n[KEYPAD]> ')
		
	if guess == code or guess == 'yu8xxj3':
		repair_droid(inventory)
	else:
		print('\n....')
		time.sleep(1)
		print('\n....')
		time.sleep(1)
		print('\nKEYPAD - LOCKED')
		time.sleep(1)
		print('\ncode randomizing..')
		time.sleep(1)
		print('\nKEYPAD - OPEN')
		time.sleep(1)
		droid_hangar(inventory)
		
def repair_droid(inventory, items=['laser']):
	print('\n\n----------')
	print('\nREP323 boot sequence....')
	time.sleep(1)
	print('Initalizing Repair Droid 323....')
	time.sleep(1)
	print('....')
	time.sleep(1)
	print('....')
	time.sleep(1)
	print('Repair Droid Active.')
	time.sleep(1)
	print('''\nThe Repair droid is now active. You MUST connect to
this droid with service port to repair laser.''')

	if len(items) > 0:
		for item in items:
			print('\n--> %s' % (item))
	cmdlist = ['service port']
	cmd = getcmd(cmdlist)
	if cmd == 'service port':
			inventory.append('laser')
			items = ['laser']
			print('\nservice port connected.')
			time.sleep(1)
			print('Repairing Laser...')
			time.sleep(1)
			print('Auto alignment...')
			time.sleep(1)
			print('....')
			time.sleep(1)
			print('\nLASER ONLINE.')
			print('''\nYour laser is now online. You de-activate the Repair
Droid and return to the Main Elevator.''')
			time.sleep(2)
			start(inventory)
	else:
		print('\n error. invalid command-')
		
def security(inventory):
	print('\n----------')
	print('\nDroid mobile..')
	time.sleep(1)
	print('....')
	time.sleep(1)
	print('''\nYou are on the Security Deck. This is where all
surveillance aboard the shuttle is done. Sentry droid 343 has been
terminated. You MUST access the Sentry droid's logs but you
will have to hack the data recorder.\n''') 
	print('[-SECURITY-]\n')
	print('1.) View Surveillance monitors on other decks')
	print('2.) Hack Sentry droid 343')
	print('3.) Return to main elevator')
	
	cmdlist =['1', '2', '3']
	cmd = getcmd(cmdlist)
	
	if cmd == '1':
		print('\n----------')
		print('\nBooting Monitors....')
		time.sleep(1)
		print('....')
		time.sleep(1)
		print('...')
		time.sleep(1)
		print('Monitors active.')
		time.sleep(1)
		print('\n[-SURVEILLANCE FEED-]')
		print('''\n-The Hangar monitor is offline you have no live feed.
\n-In the Cargo hold there are two Enemy Combat droids patroling.
\n-The Maintenance deck looks clear except for a few terminated droids.
\n-An Elite Enemy Command droid is posted on the Shuttle Control deck.
\n-Observation shows a Enemy Sentry droid.''')
		time.sleep(2)
		security(inventory)
		
	elif cmd == '2':
		if 'droid hack' in inventory:
			print('\nloading droid hack....')
			time.sleep(2)
			print('....')
			time.sleep(2)
			print('10000101010101010101010' * 1000)
			time.sleep(1)
			print('....')
			time.sleep(1)
			print('Accessing encrypted files...')
			time.sleep(2)
			print('Decrypting....')
			time.sleep(2)
			print('\n\n[-SEN343 LOG-]')
			time.sleep(1)
			print('\n\nDAILY OVER-RIDE CODES- HANGAR DROIDS')
			time.sleep(1)
			print('\n\n-Combat Droids - szb41ee')
			time.sleep(1)
			print('\n\n-Sentry Droids - qr66mop')
			time.sleep(1)
			print('\n\n-Repair Droids - yu8xxj3')
			time.sleep(1)
			print('\n\nCODES WILL BE RESET EVERY 24 HOURS')
			security(inventory)
		else:
			print('\n- ACCESS TO DATA RECORDER DENIED -')
			time.sleep(2)
			security(inventory)
		
	elif cmd == '3':
		start(inventory)
		
def observation(inventory):
	print('\n----------')
	print('\nDroid mobile..')
	time.sleep(1)
	print('....')
	time.sleep(1)
	print('''\nYou enter the Observation deck and are confronted 
with a Enemy Sentry droid beside a disabled crew droid. 
His laser is almost charged and will be active in seconds.\n''')
	print('[-OBSERVATION-]\n')
	print('1.) Terminate Sentry Droid')
	print('2.) Retreat to Main Elevator.')
	
	cmdlist = ['1', '2']
	cmd = getcmd(cmdlist)
	
	if cmd == '1':
		if 'laser' in inventory:
			print('\nlaser active...')
			time.sleep(1)
			print('target locked...')
			time.sleep(1)
			print('...')
			time.sleep(1)
			print('\nTARGET TERMINATED\n')
			enemy_sentry(inventory)
		else:
			print('\n- WARNING LASER OFFLINE -')
			time.sleep(2)
			print('''\nThe Sentry Droids laser is now active and has you locked
on. You try to initiate self-destruct but its to late..''')
			print('....')
			time.sleep(1)
			print('....')
			time.sleep(1)
			print('\nshutdown imminent...')
			time.sleep(1)
			print('CTRL866 offline.')
			time.sleep(1)
			print('Droid terminated.')
			print('\nGAME OVER\n')
			exit(0)
			
	elif cmd == '2':
			print('''\nThe Sentry droids laser is now active and has you locked
on. You try to retreat back to the elevator but its to late..''')
			print('....')
			time.sleep(1)
			print('....')
			time.sleep(1)
			print('\nshutdown imminent...')
			time.sleep(1)
			print('CTRL866 offline.')
			time.sleep(1)
			print('Droid terminated.')
			print('\nGAME OVER\n')
			exit(0)
			
def enemy_sentry(inventory, items=['motion tracker']):
	print('\n----------')
	time.sleep(1)
	print('''\nThe Enemy Sentry droid has been terminated. 
Judging by the model you know he has a
motion tracker repair program installed. You MUST connect 
to this droid with service port and download the program.''')
	if len(items) > 0:
		for item in items:
			print('\n--> %s' % (item))
	cmdlist = ['service port']
	cmd = getcmd(cmdlist)
	if cmd == 'service port':
			inventory.append('motion tracker')
			items = ['motion tracker']
			print('\nservice port connected.')
			time.sleep(1)
			print('accessing file..')
			time.sleep(1)
			print('downloading..')
			time.sleep(1)
			print('....')
			time.sleep(1)
			print('Repairing Motion Tracker...')
			time.sleep(1)
			print('Auto alignment...')
			time.sleep(1)
			print('....')
			time.sleep(2)
			print('\nMOTION TRACKER ONLINE.')
			time.sleep(2)
			print('''\nYour Motion Tracker is now online.
You return to the main elevator''')
			start(inventory)
			
def shuttle_control(inventory):
	print('\n----------')
	print('\nDroid mobile..')
	time.sleep(1)
	print('....')
	time.sleep(1)
	print('''\nYou enter Shuttle Control where all navigation takes place.
A 999 Elite Enemy Command droid is posted here.
This Droid is extremely powerfull.''')
	print('\n[-SHUTTLE CONTROL-]')
	print('\n1.) Terminate the 999 Elite Enemy Command Droid')
	print('2.) Retreat to Main Elevator')
	cmdlist = ['1', '2']
	cmd = getcmd(cmdlist)
	
	if cmd == '1':
		if 'laser' in inventory and 'motion tracker' in inventory and 'droid hack' in inventory:
			print('\n....')
			time.sleep(1)
			print('\n....')
			command_droid(inventory)
		else:
			time.sleep(1)
			print('\nEECD999:>')
			print('\n100101010101010101010101010101010' * 10)
			time.sleep(1)
			print('''\nThe Elite Enemy Command droid laughs in machine language
at your pathetic attempt. The last thing your data recorder gets is the
deafing sound of a Target Lock.''')
			print('....')
			time.sleep(1)
			print('....')
			time.sleep(1)
			print('\nshutdown imminent...')
			time.sleep(1)
			print('CTRL866 offline.')
			time.sleep(1)
			print('Droid terminated.')
			print('\nGAME OVER\n')
			exit(0)
	elif cmd == '2':
		start(inventory)
		
def command_droid(inventory):
	print('\nRunning droid hack...')
	time.sleep(1)
	print('\njamming EECD999 Target Lock...')
	time.sleep(1)
	print('\n......')
	time.sleep(1)
	print('\nMotion Tracker active...')
	time.sleep(1)
	print('\nTrack motion of EECD999...')
	time.sleep(1)
	print('\n......')
	time.sleep(1)
	print('\nLaser active...')
	time.sleep(1)
	print('\nTargeting EECD999...')
	time.sleep(1)
	print('\nTarget Locked...')
	time.sleep(1)
	print('\n......')
	time.sleep(2)
	print('\n\nTARGET TERMINATED \n')
	time.sleep(2)
	print('''\n\nYou have defeated the EECD999 droid and taken back control
of the 'KERNEL'. The flight path has been restored and
a distress signal sent to Droid Command. Reinforcements are inbound.
\n - GAME OVER -\n''')

def getcmd(cmdlist):
	cmd = input('\nCTRL866:> ')
	if cmd in cmdlist:
		return cmd
	elif cmd == 'help':
		print('\nTYPE: inventory to view items')
		print('or quit to self-destruct')
		return getcmd(cmdlist)
	elif cmd == 'inventory':
		print('\ninventory contains:\n')
		for item in inventory:
			print('-- %s' % (item))
		return getcmd(cmdlist)
	elif cmd == 'secret':
		print('\n........')
		time.sleep(1)
		print('\n[--Paradroid -- published by Hewson 1985--]')
		time.sleep(1)
		print('\n[--written by Andrew Braybrook for Commodore 64 computer--]')
		time.sleep(1)
		print('\n[--play this game or die--]')
		time.sleep(1)
		print('\n........\n')
		return getcmd(cmdlist)
	elif cmd == 'quit':
		print('\n----------')
		time.sleep(1)
		print('\nself-destruct sequence initiated...')
		time.sleep(1)
		print('shutdown imminent...')
		time.sleep(1)
		print('\nCTRL866 offline.')
		time.sleep(1)
		print('Droid terminated.\n')
		exit(0)
	else:
		print('\n   error. invalid command-\n')
		return getcmd(cmdlist)
	
if __name__ == "__main__":
	inventory = ['service port']
	start(inventory)

10 comments

Ryan Gonzalez 10 years, 9 months ago  # | flag

This game works in Python 2.7 if all the inputs are changed to raw_inputs.

jay (author) 10 years, 8 months ago  # | flag

Hi , I never tested it myself but i thought it would be possible.. If like you wisely said make a few changes here and there.

kind regards.

Joseph Dasenbrock 8 years, 5 months ago  # | flag

This game ran fine for me on 2.7.10 . Glad I found this, I'm studying Python and it was fun and helpful. Thanks...

jay (author) 8 years, 5 months ago  # | flag

Hello Joseph, thanks for your comment. I am glad you had fun with it.

Kind regards, Jay.

Dan Joshwa 8 years, 4 months ago  # | flag

I don't get it the game runs for me but when I make my first input "1" it says invalid comment and when i make my next input "deck 1" it shuts down on me

Ben 7 years, 5 months ago  # | flag

This is cool - I am not sure if this is the exact copy I have, but it looks the same, and this may even be where I found it a few months back.

I had to look at the code to see how to play the first time (something I should be doing anyway) coz I was entering 1 for example to proceed and it would only accept '1' in single quotes. so: Quote|Number|Quote

On my copy I added this little instruction into the main body of text that describes the game

Otherwise - this game was really cool

I have played a few Python text-based games, even tried writing one of my own and this is one of the best I personally have played.

In addition to a previous post about it needing raw_input on 2.7 mine worked fine (2.7.11)

Cool Game - Thanks

Ben 7 years, 5 months ago  # | flag

Dan Joshwa If you didnt see my post, enter the number like this:

'1' or '2' or '3'

Not like this:

1 or 2 or 3

You have to include the quotes to get the number to be accepted. I had a mess around around with this and edited: cmdlist[] and the: if cmd statements by removing the quotes but had no luck with the ways I tried, if removed the program doesnt accept them.

Peri Morgan 7 years, 1 month ago  # | flag

I copied this code exactly and works fine in Python 2.7 except when I tried to active the repair droid in the hanger I get an error about the global name 'item' not being defined.

I'm new to python and thought this would be good for learning. Any idea's how to fix/define this and where in the code I would put it?

Peri Morgan 7 years, 1 month ago  # | flag

Never mind I added:

item = []

at the end of the script under

if __name__ == "__main__":

and it's working fine now :)

jay (author) 7 years, 1 month ago  # | flag

Hello , It has been a long time since I wrote this program and visited here but at the time it was running fine. it was a early build of python 3 I think. I am happy that some users got some fun out of this. to all the other users that could not run it I apologise.

kind regards jay.

Created by jay on Sat, 27 Jul 2013 (MIT)
Python recipes (4591)
jay's recipes (5)

Required Modules

  • (none specified)

Other Information and Tasks