Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import exit
- from random import randint
- def death(): #defines what happens when you die
- quips = ["You died. You kinda suck at this.",
- "Nice job dying, jackass.",
- "Such a luser.",
- "I have a puppy that's better than this."] #a LIST of options for death
- print quips[randint(0,len(quips)-1)] #creates range of death options with LEN, then prints QUIP for a random number in that list
- tryagain()
- def tryagain():
- print "Try again? Y or N."
- tryagain = raw_input("> ")
- tryagain = tryagain.lower()
- while tryagain != 'y' and tryagain != 'n':
- print "You must type Y or N!"
- tryagain = raw_input("> ")
- if tryagain == 'n':
- exit(1)
- else:
- choosestart()
- def central_corridor(action): # a location on the ship. In the dictionary of locations below.
- '''The Gothons of Planet Percal #25 have invaded your ship and destroyed
- your entire crew. You are the last surviving member and your last
- mission is to get the neutron destruct bomb from the Weapons Armory,
- put it in the bridge, and blow the ship up after getting into an
- escape pod.
- You're running down the central corridor to the Weapons Armory when
- a Gothon jumps out, red scaly skin, dark grimy teeth, and evil clown costume
- flowing around his hate filled body. He's blocking the door to the
- Armory and about to pull a weapon to blast you.
- Would you like to (s)hoot, (d)odge or (t)ell a joke?'''
- #action = raw_input("> ") #options for next action.
- action = action.lower()
- if action == "s": #blah blah blah
- print '''Quick on the draw you yank out your blaster and fire it at the Gothon.
- His clown costume is flowing and moving around his body, which throws
- off your aim. Your laser hits his costume but misses him entirely. This
- completely ruins his brand new costume his mother bought him, which
- makes him fly into an insane rage and blast you repeatedly in the face until
- you are dead. Then he eats you.'''
- death()
- elif action == "d":
- print '''Like a world class boxer you dodge, weave, slip and slide right
- as the Gothon's blaster cranks a laser past your head.
- In the middle of your artful dodge your foot slips and you
- bang your head on the metal wall and pass out.
- You wake up shortly after only to die as the Gothon stomps on
- your head and eats you.'''
- death()
- elif action == "t":
- print '''Lucky for you they made you learn Gothon insults in the academy.
- You tell the one Gothon joke you know:
- Lbhe zbgure vf fb sng, jura fur fvgf nebhaq gur ubhfr, fur fvgf nebhaq gur ubhfr.
- The Gothon stops, tries not to laugh, then busts out laughing and can't move.
- While he's laughing you run up and shoot him square in the head
- putting him down, then jump through the Weapon Armory door.'''
- return 'laser_weapon_armory'
- else:
- print "DOES NOT COMPUTE!"
- return 'central_corridor'
- def laser_weapon_armory(guess):
- '''You do a dive roll into the Weapon Armory, crouch
- and scan the room for more Gothons that might be hiding.
- It's dead quiet, too quiet. You stand up and run to the far side of the room
- and find the neutron bomb in its container. There's a keypad lock on the box
- and you need the code to get the bomb out. If you get the code
- wrong 10 times then the lock closes forever and you can't
- get the bomb. The code is 3 digits, with each digit being either 1 or 2.
- The machine buzzes and says 'Pants may pass!\''''
- code = "%d%d%d" % (randint(1,2), randint(1,2), randint(1,2))
- #guess = raw_input("[keypad]> ")
- guesses = 0
- while guess != code and guess != 'pants' and guesses < 10:
- print "BZZZZEDDD!"
- guesses += 1
- guess = raw_input("[keypad]> ")
- if guess == code or guess == 'pants' or guess == 'Pants':
- print '''The container clicks open and the seal breaks, letting gas out.
- You grab the neutron bomb and run as fast as you can to the
- bridge where you must place it in the right spot.'''
- return 'the_bridge'
- else:
- print '''The lock buzzes one last time and then you hear a sickening
- melting sound as the mechanism is fused together.
- You decide to sit there, and finally the Gothons blow up the
- ship from their ship and you die.'''
- death()
- def the_bridge(action):
- '''You burst onto the Bridge with the netron destruct bomb
- under your arm and surprise 5 Gothons who are trying to
- take control of the ship. Each of them has an even uglier
- clown costume than the last. They haven't pulled their
- weapons out yet, as they see the active bomb under your
- arm and don't want to set it off. Do you want to(t)hrow the bomb
- or (s)et the bomb down gently?'''
- action = action.lower()
- while action != 't' and action != 's':
- print "You have to pick T or S!"
- action = raw_input("(t)hrow the bomb or (s)et the bomb down gently? ")
- if action == "t":
- print'''In a panic you throw the bomb at the group of Gothons
- and make a leap for the door. Right as you drop it a
- Gothon shoots you right in the back killing you.
- As you die you see another Gothon frantically try to disarm
- the bomb. You die knowing they will probably blow up when
- it goes off.'''
- death()
- elif action == "s":
- print '''You point your blaster at the bomb under your arm
- and the Gothons put their hands up and start to sweat.
- You inch backward to the door, open it, and then carefully
- place the bomb on the floor, pointing your blaster at it.
- You then jump back through the door, punch the close button
- and blast the lock so the Gothons can't get out.
- Now that the bomb is placed you run to the escape pod to
- get off this tin can.'''
- return 'escape_pod'
- else:
- print "DOES NOT COMPUTE!"
- return "the_bridge"
- def escape_pod(guess):
- '''You rush through the ship desperately trying to make it to
- the escape pod before the whole ship explodes. It seems like
- hardly any Gothons are on the ship, so your run is clear of
- interference. You get to the chamber with the escape pods, and
- now need to pick one to take. Some of them could be damaged
- but you don't have time to look. There's 5 pods, which one
- do you take?'''
- good_pod = randint(1,5)
- try:
- guess = int(guess)
- if guess <1 or guess >5:
- raise ValueError
- except ValueError:
- print "You must choose a number between 1 and 5!"
- return 'escape_pod'
- if guess != good_pod and good_pod >1 and good_pod <5:
- 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)
- guess = raw_input("> ")
- elif guess != good_pod and good_pod == 1:
- print "Wait! The undamaged pod seems to be the one on the left."
- guess = raw_input("> ")
- elif guess != good_pod and good_pod == 5:
- print "Wait! The undamaged pod seems to be the furthest to the right."
- guess = raw_input("> ")
- if int(guess) != good_pod:
- print "You jump into pod %s and hit the eject button." % guess
- print "The pod escapes out into the void of space, then"
- print "implodes as the hull ruptures, crushing your body"
- print "into jam jelly."
- death() #changed because return death screwed up the raw_input and print I included in the runner.
- else:
- print "You jump into pod %s and hit the eject button." % guess
- print "The pod easily slides out into space heading to"
- print "the planet below. As it flies to the planet, you look"
- print "back and see your ship implode then explode like a"
- print "bright star, taking out the Gothon ship at the same"
- print "time. You won!"
- tryagain()
- ROOMS = {
- 'death': death,
- 'central_corridor': central_corridor,
- 'laser_weapon_armory': laser_weapon_armory,
- 'the_bridge': the_bridge,
- 'escape_pod': escape_pod
- }
- def runner(mappy, start): #the runner function starts with the parameters "mappy" and "start".
- next = start #at beginning, next = central_corridor. As different values are passed, this changes.
- #so whatever value you pass to runner at the beginning in its parameters will be your first "next".
- #I should be able to set the start room with a raw_input that lets me pick the paramenter, then.
- while True: #keep going forever until pushed into a function with exit at the end
- room = mappy[next] #assign room the value of the key currently assigned to next in the map (ROOMS)
- #so at the beginning, room = central_corridor (the value for the key 'central_corridor')
- print "\n--------" #line break for styling
- print room.__doc__
- nextstep = raw_input ("> ")
- next = room(nextstep) #changes the value of next, which will change the key for the value in room = above. Why the brackets?
- #WITHOUT the brackets, I get a KeyError -- so the parentheses are necessary to make this recognized as a function
- #and not just a text string inside the dictionary?
- #okay, see http://stackoverflow.com/questions/9517612/learning-python-the-hard-way-exercise-41-headache
- #apparently when next calls the function, the full function runs, and the "return" at the end of the function
- #is passed to "next". That "return" value is then processed as "next," and the "while" loop keeps everything
- #going until the exit() is hit at the end of one of the functions! BRAIN EXPLODING
- def choosestart():
- print '''What room would you like to start in?
- (a) central corridor
- (b) armoury
- (c) the bridge
- (d) escape pods'''
- startchoice = raw_input ("> ")
- if startchoice == "a":
- runner(ROOMS,'central_corridor')
- elif startchoice == "b":
- runner(ROOMS,'laser_weapon_armory')
- elif startchoice == "c":
- runner(ROOMS,'the_bridge')
- elif startchoice == "d":
- runner(ROOMS,'escape_pod')
- else:
- print "choose a, b, c or d!"
- choosestart()
- choosestart()
Advertisement
Add Comment
Please, Sign In to add comment