Guest User

Untitled

a guest
Jul 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. from PrincessRoom import PrincessRoom
  2. import sys
  3. class Game(object):
  4.     def __init__(self,rooms):
  5.         self.rooms = rooms
  6.  
  7.     def play(self):
  8.         for room in self.rooms:
  9.             if(room.play()):
  10.                 continue
  11.             else:
  12.                 print("Game Over!")
  13.                 sys.exit(1)
  14.         print("You win!")
  15.    
  16. if __name__=="__main__":
  17.     G = Game([PrincessRoom()])
  18.     G.play()
  19.  
  20. class GameStep(object):
  21.     def __init__(self,question=None,correct_choice=None,live=None,death=None):
  22.         self.question = question
  23.         self.correct_choice = correct_choice
  24.         self.live = live
  25.         self.death = death
  26.        
  27.  
  28.  
  29. class PrincessRoom(object):
  30.     def __init__(self):
  31.         self.steps = []
  32.         self.steps.append(GameStep("Red pill or blue pill?",
  33.                                             "Red",
  34.                                             "you stay in Wonderland and I show you how deep the rabbit-hole goes",
  35.                                             "the story ends, you wake up in your bed and believe whatever you want to believe"))
  36.         self.steps.append(GameStep("Up or down?",
  37.                                             "Up",
  38.                                             "Up is way cooler than down",
  39.                                             "Dude, you've fallen and you can't get up"))
  40.         self.steps.append(GameStep("Left or right?",
  41.                                             "Left",
  42.                                             "Lefty loosey, You return from Princess' Lair!",
  43.                                             "Righty tighty, you stay in the Room....FOREVER"))
  44.  
  45.     def play(self):
  46.         for step in self.steps:
  47.             print(step.question)
  48.             choice = raw_input("> ")
  49.             if choice.lower() == step.correct_choice.lower(): #use lower so all string comparisons are lowercase
  50.                 print(step.live)
  51.                 continue
  52.             else:
  53.                 print(step.death)
  54.                 return False
  55.         return True
Advertisement
Add Comment
Please, Sign In to add comment