Advertisement
Guest User

Untitled

a guest
Aug 4th, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from sys import exit
  2. from random import randint
  3.  
  4. class Scene(object):
  5.     def enter(self):
  6.         print ("This scene is not yet configured. Subclass it and implement enter().")
  7.         exit(0)
  8.  
  9. class Engine(object):
  10.  
  11.     print ("Inside engine class")
  12.     def __init__(self, scene_map):
  13.         self.scene_map = scene_map
  14.         print self
  15.     def play(self):
  16.         print "inside play ",self
  17.         flag = True
  18.         current_scene = self.scene_map.opening_scene()
  19.         if current_scene =="finish":
  20.             flag = False
  21.         while flag:
  22.             print "\n--------"
  23.             next_scene_name = current_scene.enter()
  24.             if next_scene_name == "finish":
  25.                 exit(0)
  26.             else:
  27.                 current_scene = self.scene_map.next_scene(next_scene_name)
  28.  
  29. class Death(Scene):
  30.     quips = [
  31.     "You died. You kinda suck at this.",
  32.     "Your mom would be proud...if she were smarter.",
  33.     "Such a luser.",
  34.     "I have a small puppy that's better at this."]
  35.     def enter(self):
  36.         print Death.quips[randint(0, len(self.quips)-1)]
  37.         exit(1)
  38.  
  39. class CentralCorridor(Scene):
  40.     def enter(self):
  41.  
  42.         print ("""1.Shoot!\n2.dodge\n3.tell joke""")
  43.         action = raw_input("> ")
  44.         if action== "shoot!":
  45.             return 'death'
  46.         elif action == "dodge!":
  47.             return 'death'
  48.         elif action == "tell a joke":
  49.             return 'laser_weapon_armory'
  50.         else:
  51.             print "DOES NOT COMPUTE!"
  52.             return 'central_corridor'
  53.  
  54.  
  55.  
  56. class LaserWeaponArmory(Scene):
  57.     def enter(self):
  58.         print("Enter three digit code")
  59.         code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
  60.         print code
  61.         guess = raw_input("[keypad]> ")
  62.         guesses = 0
  63.         while guess != code and guesses < 10:
  64.             print ("BZZZZEDDD!")
  65.             guesses += 1
  66.             guess = raw_input("[keypad]> ")
  67.         if guess == code:
  68.             return 'the_bridge'
  69.         else:
  70.             return 'death'
  71.  
  72. class TheBridge(Scene):
  73.     print("Do you...")
  74.     print ("1. Throw bomb \n 2. slowly place the bomb" )
  75.     def enter(self):
  76.         action = raw_input("> ")
  77.         if action == "throw the bomb":
  78.             return 'death'
  79.         elif action == "slowly place the bomb":
  80.             return 'escape_pod'
  81.         else:
  82.             print "DOES NOT COMPUTE!"
  83.             return "the_bridge"
  84.  
  85. class EscapePod(Scene):
  86.     def enter(self):
  87.         print ("There's 5 pods, which one")
  88.         print ("do you take?")
  89.         good_pod = randint(1,5)
  90.         print good_pod
  91.         guess = raw_input("[pod #]> ")
  92.         if int(guess) != good_pod:
  93.             return 'death'
  94.         else:
  95.             return 'finish'
  96.  
  97. class Finish(Scene):
  98.     def enter(self):
  99.         print "You return to your planet below ,you are hero now "
  100.  
  101. class Map(object):
  102.     print "inside map class"
  103.     scenes = {
  104.                 'central_corridor': CentralCorridor(),
  105.                 'laser_weapon_armory': LaserWeaponArmory(),
  106.                 'the_bridge': TheBridge(),
  107.                 'escape_pod': EscapePod(),
  108.                 'death': Death(),
  109.                 'finish':Finish()
  110.             }
  111.     def __init__(self, start_scene):
  112.         print start_scene
  113.         self.start_scene = start_scene
  114.     def next_scene(self, scene_name):
  115.         return Map.scenes.get(scene_name)
  116.     def opening_scene(self):
  117.         print "inside opening scene"
  118.         return self.next_scene(self.start_scene)
  119. a_map = Map("central_corridor")
  120. a_game = Engine(a_map)
  121. a_game.play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement