Hack A Text Based Game
#droids.py import time import random from random import randint print ( ' n '. 100 ) print ( ' nn -Droids: by jay: type help-' ) print ( ' nnn -' ) print ( ' DROIDS' ) print ( '-' ) print ( ' n: cytek inc.' Sleep ( 1 ) print ( ' n CTRL866 Re-Boot Sequence.' Sleep ( 1 ) print ( ' n Initalizing Control Droid 866.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( '.'
Sleep ( 1 ) print ( 'Laser offline.' Sleep ( 1 ) print ( 'Motion Tracker offline.'
Sleep ( 1 ) print ( ' n Service Port avaliable.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( '.' ) print ( ' n Control Droid Active.' Sleep ( 1 ) print ( ' nn You 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 ( ' n Droid mobile.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n -MAIN ELEVATOR-' ) print ( ' n 1.) 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': cargohold ( inventory ) elif cmd '4': if 'laser' in inventory: print ( ' n - DECK 4 - DROID HANGAR LOCKED -' ) time. Sleep ( 2 ) start ( inventory ) else: droidhangar ( inventory ) elif cmd '5': shuttlecontrol ( 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 ( ' n Droid mobile.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n This 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': crewdroid ( inventory ) elif cmd '2': start ( inventory ) def crewdroid ( inventory, items = 'droid hack' ): print ( ' n -' ) print ( ' n 716 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 ( ' nn 1.) Exit.' ) cmdlist = 'service port', '1' cmd = getcmd ( cmdlist ) if cmd 'service port': inventory.
Append ( 'droid hack' ) items = 'droid hack' print ( ' n service port connected.' Sleep ( 1 ) print ( 'accessing file.'
Sleep ( 1 ) print ( 'downloading.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n download complete.' ) print ( ' n You have the droid hack program and return' ) print ( 'to the Main Elevator.' Sleep ( 2 ) start ( inventory ) elif cmd '1': maintenance ( inventory ) else: print ( ' n error.
Invalid command-' ) def cargohold ( inventory ): print ( ' n -' ) print ( ' n Droid mobile.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n You 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 ( '.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n shutdown imminent.' Sleep ( 1 ) print ( 'CTRL866 offline.'
Sleep ( 1 ) print ( 'Droid terminated.' ) print ( ' n GAME OVER n ' ) exit ( 0 ) def droidhangar ( inventory ): print ( ' n -' ) print ( ' n Droid mobile.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n The 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 ( ' n 1.) Repair Droid 3 digit code' ) print ( '2.) Return to Main Elevator' ) cmdlist = '1', '2' cmd = getcmd ( cmdlist ) if cmd '1': accesscode ( inventory ) elif cmd '2': start ( inventory ) def accesscode ( 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 ' ) if guess code or guess 'yu8xxj3': repairdroid ( inventory ) else: print ( ' n.' Sleep ( 1 ) print ( ' n.' Sleep ( 1 ) print ( ' n KEYPAD - LOCKED' ) time. Sleep ( 1 ) print ( ' n code randomizing.' Sleep ( 1 ) print ( ' n KEYPAD - OPEN' ) time. Sleep ( 1 ) droidhangar ( inventory ) def repairdroid ( inventory, items = 'laser' ): print ( ' nn -' ) print ( ' n REP323 boot sequence.'
Sleep ( 1 ) print ( 'Initalizing Repair Droid 323.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( 'Repair Droid Active.' Sleep ( 1 ) print ( ' n The 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 ( ' n service port connected.'
Sleep ( 1 ) print ( 'Repairing Laser.' Sleep ( 1 ) print ( 'Auto alignment.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n LASER ONLINE.' ) print ( ' n Your laser is now online. You de-activate the Repair Droid and return to the Main Elevator.' Sleep ( 2 ) start ( inventory ) else: print ( ' n error.
Invalid command-' ) def security ( inventory ): print ( ' n -' ) print ( ' n Droid mobile.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n You 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 ( ' n Booting Monitors.'
Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( 'Monitors active.'
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.' Sleep ( 2 ) security ( inventory ) elif cmd '2': if 'droid hack' in inventory: print ( ' n loading droid hack.' Sleep ( 2 ) print ( '.' Sleep ( 2 ) print ( '010'.
1000 ) time. Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( 'Accessing encrypted files.' Sleep ( 2 ) print ( 'Decrypting.' Sleep ( 2 ) print ( ' nn -SEN343 LOG-' ) time. Sleep ( 1 ) print ( ' nn DAILY OVER-RIDE CODES- HANGAR DROIDS' ) time.
Sleep ( 1 ) print ( ' nn -Combat Droids - szb41ee' ) time. Sleep ( 1 ) print ( ' nn -Sentry Droids - qr66mop' ) time. Sleep ( 1 ) print ( ' nn -Repair Droids - yu8xxj3' ) time. Sleep ( 1 ) print ( ' nn CODES 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 ( ' n Droid mobile.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n You 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 ( ' n laser active.' Sleep ( 1 ) print ( 'target locked.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n TARGET TERMINATED n ' ) enemysentry ( inventory ) else: print ( ' n - WARNING LASER OFFLINE -' ) time. Sleep ( 2 ) print ( ' n The Sentry Droids laser is now active and has you locked on. You try to initiate self-destruct but its to late.' ' ) print ( '.'
Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n shutdown imminent.' Sleep ( 1 ) print ( 'CTRL866 offline.' Sleep ( 1 ) print ( 'Droid terminated.' ) print ( ' n GAME OVER n ' ) exit ( 0 ) elif cmd '2': print ( ' n The Sentry droids laser is now active and has you locked on.
You try to retreat back to the elevator but its to late.' ' ) print ( '.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n shutdown imminent.'
Sleep ( 1 ) print ( 'CTRL866 offline.' Sleep ( 1 ) print ( 'Droid terminated.' ) print ( ' n GAME OVER n ' ) exit ( 0 ) def enemysentry ( inventory, items = 'motion tracker' ): print ( ' n -' ) time.
Sleep ( 1 ) print ( ' n The 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 ( ' n service port connected.' Sleep ( 1 ) print ( 'accessing file.'
Sleep ( 1 ) print ( 'downloading.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( 'Repairing Motion Tracker.'
Sleep ( 1 ) print ( 'Auto alignment.' Sleep ( 1 ) print ( '.' Sleep ( 2 ) print ( ' n MOTION TRACKER ONLINE.' Sleep ( 2 ) print ( ' n Your Motion Tracker is now online. You return to the main elevator' ) start ( inventory ) def shuttlecontrol ( inventory ): print ( ' n -' ) print ( ' n Droid mobile.' Sleep ( 1 ) print ( '.'
Sleep ( 1 ) print ( ' n You 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 ( ' n 1.) 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.'
Sleep ( 1 ) print ( ' n.' ) commanddroid ( inventory ) else: time.
Sleep ( 1 ) print ( ' n EECD999:' ) print ( ' n 010'. 10 ) time. Sleep ( 1 ) print ( ' n The 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 ( '.' Sleep ( 1 ) print ( '.' Sleep ( 1 ) print ( ' n shutdown imminent.' Sleep ( 1 ) print ( 'CTRL866 offline.' Sleep ( 1 ) print ( 'Droid terminated.'
) print ( ' n GAME OVER n ' ) exit ( 0 ) elif cmd '2': start ( inventory ) def commanddroid ( inventory ): print ( ' n Running droid hack.' Sleep ( 1 ) print ( ' n jamming EECD999 Target Lock.' Sleep ( 1 ) print ( ' n.' Sleep ( 1 ) print ( ' n Motion Tracker active.'
Sleep ( 1 ) print ( ' n Track motion of EECD999.' Sleep ( 1 ) print ( ' n.' Sleep ( 1 ) print ( ' n Laser active.' Sleep ( 1 ) print ( ' n Targeting EECD999.'
Sleep ( 1 ) print ( ' n Target Locked.' Sleep ( 1 ) print ( ' n.'
How To Make A Text Based Game
Sleep ( 2 ) print ( ' nn TARGET TERMINATED n ' ) time. Sleep ( 2 ) print ( ' nn You 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 ( ' n CTRL866: ' ) if cmd in cmdlist: return cmd elif cmd 'help': print ( ' n TYPE: inventory to view items' ) print ( 'or quit to self-destruct' ) return getcmd ( cmdlist ) elif cmd 'inventory': print ( ' n inventory contains: n ' ) for item in inventory: print ( '-%s '% ( item )) return getcmd ( cmdlist ) elif cmd 'secret': print ( ' n.' 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 ( ' n self-destruct sequence initiated.' Sleep ( 1 ) print ( 'shutdown imminent.'
Sleep ( 1 ) print ( ' n CTRL866 offline.' 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 ). 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 QuoteOn my copy I added this little instruction into the main body of text that describes the gameOtherwise - this game was really coolI 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 rawinput on 2.7 mine worked fine (2.7.11)Cool Game - Thanks.