Advertisement
Guest User

exercise 43

a guest
Jul 18th, 2013
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. class Scene(object):
  2.  
  3.     def enter(self):
  4.         print "This scene is not yet configured. Subclass it and implement enter()."
  5.         exit(1)
  6.        
  7.  
  8. class Engine(object):
  9.    
  10.     def __init__(self, scene_map):
  11.         self.scene_map = scene_map
  12.        
  13.     def play(self):
  14.         current_scene = self.scene_map.opening_scene()
  15.        
  16.         while True:
  17.             print "\n----------"
  18.             next_scene_name = current_scene.enter()
  19.             current_scene = self.scene_map.next_scene(next_scene_name)
  20.        
  21. class Death(Scene):
  22.    
  23.    
  24.    
  25.     def enter(self):
  26.         print "death text"
  27.         exit(1)
  28.        
  29. class CentralCorridor(Scene):
  30.    
  31.     def enter(self):
  32.         print "loads of text goes here"
  33.        
  34.        
  35.         action = raw_input("> ")
  36.                
  37.         if action == "dodge":
  38.             print "loads of text goes here"
  39.             return 'death'
  40.            
  41.        
  42.         elif action == 'tell a joke':
  43.             print "loads of text goes here"
  44.             return 'laser_weapon_armory'
  45.            
  46.         else:
  47.             print "DOES NOT COMPUTE!"
  48.             return 'central_corridor'
  49.        
  50.        
  51. class Map(object):
  52.    
  53.     scenes = {
  54.         'central_corridor': CentralCorridor(),
  55.         'laser_weapon_armory': LaserWeaponArmory(),
  56.         'the_bridge': TheBridge(),
  57.         'escape_pod': EscapePod(),
  58.         'death': Death()
  59.     }
  60.    
  61.    
  62.     def __init__(self, start_scene):
  63.         self.start_scene = start_scene
  64.        
  65.     def next_scene(self, scene_name):
  66.         return Map.scenes.get(scene_name)
  67.        
  68.     def opening_scene(self):
  69.         return self.next_scene(self.start_scene)
  70.        
  71. a_map = Map('central_corridor')
  72. a_game = Engine(a_map)
  73. a_game.play()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement