Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import exit
- from random import randint
- class Scene(object):
- def enter(self):
- print ("This scene is not yet configured. Subclass it and implement enter().")
- exit(0)
- class Engine(object):
- print ("Inside engine class")
- def __init__(self, scene_map):
- self.scene_map = scene_map
- print self
- def play(self):
- print "inside play ",self
- flag = True
- current_scene = self.scene_map.opening_scene()
- if current_scene =="finish":
- flag = False
- while flag:
- print "\n--------"
- next_scene_name = current_scene.enter()
- if next_scene_name == "finish":
- exit(0)
- else:
- current_scene = self.scene_map.next_scene(next_scene_name)
- class Death(Scene):
- quips = [
- "You died. You kinda suck at this.",
- "Your mom would be proud...if she were smarter.",
- "Such a luser.",
- "I have a small puppy that's better at this."]
- def enter(self):
- print Death.quips[randint(0, len(self.quips)-1)]
- exit(1)
- class CentralCorridor(Scene):
- def enter(self):
- print ("""1.Shoot!\n2.dodge\n3.tell joke""")
- action = raw_input("> ")
- if action== "shoot!":
- return 'death'
- elif action == "dodge!":
- return 'death'
- elif action == "tell a joke":
- return 'laser_weapon_armory'
- else:
- print "DOES NOT COMPUTE!"
- return 'central_corridor'
- class LaserWeaponArmory(Scene):
- def enter(self):
- print("Enter three digit code")
- code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
- print code
- guess = raw_input("[keypad]> ")
- guesses = 0
- while guess != code and guesses < 10:
- print ("BZZZZEDDD!")
- guesses += 1
- guess = raw_input("[keypad]> ")
- if guess == code:
- return 'the_bridge'
- else:
- return 'death'
- class TheBridge(Scene):
- print("Do you...")
- print ("1. Throw bomb \n 2. slowly place the bomb" )
- def enter(self):
- action = raw_input("> ")
- if action == "throw the bomb":
- return 'death'
- elif action == "slowly place the bomb":
- return 'escape_pod'
- else:
- print "DOES NOT COMPUTE!"
- return "the_bridge"
- class EscapePod(Scene):
- def enter(self):
- print ("There's 5 pods, which one")
- print ("do you take?")
- good_pod = randint(1,5)
- print good_pod
- guess = raw_input("[pod #]> ")
- if int(guess) != good_pod:
- return 'death'
- else:
- return 'finish'
- class Finish(Scene):
- def enter(self):
- print "You return to your planet below ,you are hero now "
- class Map(object):
- print "inside map class"
- scenes = {
- 'central_corridor': CentralCorridor(),
- 'laser_weapon_armory': LaserWeaponArmory(),
- 'the_bridge': TheBridge(),
- 'escape_pod': EscapePod(),
- 'death': Death(),
- 'finish':Finish()
- }
- def __init__(self, start_scene):
- print start_scene
- self.start_scene = start_scene
- def next_scene(self, scene_name):
- return Map.scenes.get(scene_name)
- def opening_scene(self):
- print "inside opening scene"
- return self.next_scene(self.start_scene)
- a_map = Map("central_corridor")
- a_game = Engine(a_map)
- a_game.play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement