mattshepherd

LPTHW ex41_2

Mar 10th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.46 KB | None | 0 0
  1. from sys import exit
  2. from random import randint
  3.  
  4. def death(): #defines what happens when you die
  5. quips = ["You died. You kinda suck at this.",
  6. "Nice job dying, jackass.",
  7. "Such a luser.",
  8. "I have a puppy that's better than this."] #a LIST of options for death
  9. print quips[randint(0,len(quips)-1)] #creates range of death options with LEN, then prints QUIP for a random number in that list
  10. tryagain()
  11.  
  12. def tryagain():
  13. print "Try again? Y or N."
  14. tryagain = raw_input("> ")
  15. tryagain = tryagain.lower()
  16. while tryagain != 'y' and tryagain != 'n':
  17. print "You must type Y or N!"
  18. tryagain = raw_input("> ")
  19. if tryagain == 'n':
  20. exit(1)
  21. else:
  22. choosestart()
  23.  
  24. def central_corridor(action): # a location on the ship. In the dictionary of locations below.
  25. '''The Gothons of Planet Percal #25 have invaded your ship and destroyed
  26. your entire crew. You are the last surviving member and your last
  27. mission is to get the neutron destruct bomb from the Weapons Armory,
  28. put it in the bridge, and blow the ship up after getting into an
  29. escape pod.
  30.  
  31. You're running down the central corridor to the Weapons Armory when
  32. a Gothon jumps out, red scaly skin, dark grimy teeth, and evil clown costume
  33. flowing around his hate filled body. He's blocking the door to the
  34. Armory and about to pull a weapon to blast you.
  35.  
  36. Would you like to (s)hoot, (d)odge or (t)ell a joke?'''
  37. #action = raw_input("> ") #options for next action.
  38. action = action.lower()
  39. if action == "s": #blah blah blah
  40. print '''Quick on the draw you yank out your blaster and fire it at the Gothon.
  41. His clown costume is flowing and moving around his body, which throws
  42. off your aim. Your laser hits his costume but misses him entirely. This
  43. completely ruins his brand new costume his mother bought him, which
  44. makes him fly into an insane rage and blast you repeatedly in the face until
  45. you are dead. Then he eats you.'''
  46. death()
  47.  
  48. elif action == "d":
  49. print '''Like a world class boxer you dodge, weave, slip and slide right
  50. as the Gothon's blaster cranks a laser past your head.
  51. In the middle of your artful dodge your foot slips and you
  52. bang your head on the metal wall and pass out.
  53. You wake up shortly after only to die as the Gothon stomps on
  54. your head and eats you.'''
  55. death()
  56.  
  57. elif action == "t":
  58. print '''Lucky for you they made you learn Gothon insults in the academy.
  59. You tell the one Gothon joke you know:
  60. Lbhe zbgure vf fb sng, jura fur fvgf nebhaq gur ubhfr, fur fvgf nebhaq gur ubhfr.
  61. The Gothon stops, tries not to laugh, then busts out laughing and can't move.
  62. While he's laughing you run up and shoot him square in the head
  63. putting him down, then jump through the Weapon Armory door.'''
  64. return 'laser_weapon_armory'
  65.  
  66. else:
  67. print "DOES NOT COMPUTE!"
  68. return 'central_corridor'
  69.  
  70. def laser_weapon_armory(guess):
  71. '''You do a dive roll into the Weapon Armory, crouch
  72. and scan the room for more Gothons that might be hiding.
  73. It's dead quiet, too quiet. You stand up and run to the far side of the room
  74. and find the neutron bomb in its container. There's a keypad lock on the box
  75. and you need the code to get the bomb out. If you get the code
  76. wrong 10 times then the lock closes forever and you can't
  77. get the bomb. The code is 3 digits, with each digit being either 1 or 2.
  78. The machine buzzes and says 'Pants may pass!\''''
  79. code = "%d%d%d" % (randint(1,2), randint(1,2), randint(1,2))
  80. #guess = raw_input("[keypad]> ")
  81. guesses = 0
  82.  
  83. while guess != code and guess != 'pants' and guesses < 10:
  84. print "BZZZZEDDD!"
  85. guesses += 1
  86. guess = raw_input("[keypad]> ")
  87.  
  88. if guess == code or guess == 'pants' or guess == 'Pants':
  89. print '''The container clicks open and the seal breaks, letting gas out.
  90. You grab the neutron bomb and run as fast as you can to the
  91. bridge where you must place it in the right spot.'''
  92. return 'the_bridge'
  93. else:
  94. print '''The lock buzzes one last time and then you hear a sickening
  95. melting sound as the mechanism is fused together.
  96. You decide to sit there, and finally the Gothons blow up the
  97. ship from their ship and you die.'''
  98. death()
  99.  
  100.  
  101. def the_bridge(action):
  102. '''You burst onto the Bridge with the netron destruct bomb
  103. under your arm and surprise 5 Gothons who are trying to
  104. take control of the ship. Each of them has an even uglier
  105. clown costume than the last. They haven't pulled their
  106. weapons out yet, as they see the active bomb under your
  107. arm and don't want to set it off. Do you want to(t)hrow the bomb
  108. or (s)et the bomb down gently?'''
  109. action = action.lower()
  110.  
  111. while action != 't' and action != 's':
  112. print "You have to pick T or S!"
  113. action = raw_input("(t)hrow the bomb or (s)et the bomb down gently? ")
  114.  
  115. if action == "t":
  116. print'''In a panic you throw the bomb at the group of Gothons
  117. and make a leap for the door. Right as you drop it a
  118. Gothon shoots you right in the back killing you.
  119. As you die you see another Gothon frantically try to disarm
  120. the bomb. You die knowing they will probably blow up when
  121. it goes off.'''
  122. death()
  123.  
  124. elif action == "s":
  125. print '''You point your blaster at the bomb under your arm
  126. and the Gothons put their hands up and start to sweat.
  127. You inch backward to the door, open it, and then carefully
  128. place the bomb on the floor, pointing your blaster at it.
  129. You then jump back through the door, punch the close button
  130. and blast the lock so the Gothons can't get out.
  131. Now that the bomb is placed you run to the escape pod to
  132. get off this tin can.'''
  133. return 'escape_pod'
  134. else:
  135. print "DOES NOT COMPUTE!"
  136. return "the_bridge"
  137.  
  138. def escape_pod(guess):
  139. '''You rush through the ship desperately trying to make it to
  140. the escape pod before the whole ship explodes. It seems like
  141. hardly any Gothons are on the ship, so your run is clear of
  142. interference. You get to the chamber with the escape pods, and
  143. now need to pick one to take. Some of them could be damaged
  144. but you don't have time to look. There's 5 pods, which one
  145. do you take?'''
  146. good_pod = randint(1,5)
  147.  
  148. try:
  149. guess = int(guess)
  150. if guess <1 or guess >5:
  151. raise ValueError
  152. except ValueError:
  153. print "You must choose a number between 1 and 5!"
  154. return 'escape_pod'
  155.  
  156. if guess != good_pod and good_pod >1 and good_pod <5:
  157. print "Wait! The undamaged pod seems to be to the right of Bay #%d and the left of Bay #%d." % (good_pod-1, good_pod+1)
  158. guess = raw_input("> ")
  159. elif guess != good_pod and good_pod == 1:
  160. print "Wait! The undamaged pod seems to be the one on the left."
  161. guess = raw_input("> ")
  162. elif guess != good_pod and good_pod == 5:
  163. print "Wait! The undamaged pod seems to be the furthest to the right."
  164. guess = raw_input("> ")
  165.  
  166. if int(guess) != good_pod:
  167. print "You jump into pod %s and hit the eject button." % guess
  168. print "The pod escapes out into the void of space, then"
  169. print "implodes as the hull ruptures, crushing your body"
  170. print "into jam jelly."
  171. death() #changed because return death screwed up the raw_input and print I included in the runner.
  172. else:
  173. print "You jump into pod %s and hit the eject button." % guess
  174. print "The pod easily slides out into space heading to"
  175. print "the planet below. As it flies to the planet, you look"
  176. print "back and see your ship implode then explode like a"
  177. print "bright star, taking out the Gothon ship at the same"
  178. print "time. You won!"
  179. tryagain()
  180.  
  181.  
  182. ROOMS = {
  183. 'death': death,
  184. 'central_corridor': central_corridor,
  185. 'laser_weapon_armory': laser_weapon_armory,
  186. 'the_bridge': the_bridge,
  187. 'escape_pod': escape_pod
  188. }
  189.  
  190.  
  191. def runner(mappy, start): #the runner function starts with the parameters "mappy" and "start".
  192. next = start #at beginning, next = central_corridor. As different values are passed, this changes.
  193. #so whatever value you pass to runner at the beginning in its parameters will be your first "next".
  194. #I should be able to set the start room with a raw_input that lets me pick the paramenter, then.
  195. while True: #keep going forever until pushed into a function with exit at the end
  196. room = mappy[next] #assign room the value of the key currently assigned to next in the map (ROOMS)
  197. #so at the beginning, room = central_corridor (the value for the key 'central_corridor')
  198. print "\n--------" #line break for styling
  199. print room.__doc__
  200. nextstep = raw_input ("> ")
  201. next = room(nextstep) #changes the value of next, which will change the key for the value in room = above. Why the brackets?
  202. #WITHOUT the brackets, I get a KeyError -- so the parentheses are necessary to make this recognized as a function
  203. #and not just a text string inside the dictionary?
  204. #okay, see http://stackoverflow.com/questions/9517612/learning-python-the-hard-way-exercise-41-headache
  205. #apparently when next calls the function, the full function runs, and the "return" at the end of the function
  206. #is passed to "next". That "return" value is then processed as "next," and the "while" loop keeps everything
  207. #going until the exit() is hit at the end of one of the functions! BRAIN EXPLODING
  208.  
  209. def choosestart():
  210. print '''What room would you like to start in?
  211. (a) central corridor
  212. (b) armoury
  213. (c) the bridge
  214. (d) escape pods'''
  215.  
  216. startchoice = raw_input ("> ")
  217.  
  218. if startchoice == "a":
  219. runner(ROOMS,'central_corridor')
  220. elif startchoice == "b":
  221. runner(ROOMS,'laser_weapon_armory')
  222. elif startchoice == "c":
  223. runner(ROOMS,'the_bridge')
  224. elif startchoice == "d":
  225. runner(ROOMS,'escape_pod')
  226. else:
  227. print "choose a, b, c or d!"
  228. choosestart()
  229.  
  230. choosestart()
Advertisement
Add Comment
Please, Sign In to add comment