SHARE
TWEET

asf

a guest Jun 27th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. inventory = []
  2.  
  3.  
  4. class InputHandler:
  5.  
  6.     @staticmethod
  7.     def get_input():
  8.         command = input()
  9.         command_array = command.split()
  10.         return command_array
  11.  
  12.     @staticmethod
  13.     def check_room_input(command_array):
  14.         if command_array[0] == 'go':
  15.             Basement.handle_go(command_array)
  16.         elif command_array[0] == 'enter':
  17.             Basement.handle_enter(command_array)
  18.         elif command_array[0] == 'take':
  19.             return True
  20.         elif command_array[0] == 'drop':
  21.             Basement.handle_drop(command_array)
  22.         elif command_array[0].lower() == 'help':
  23.             Basement.handle_help()
  24.             return True
  25.         elif command_array[0] == 'inventory':
  26.             print(inventory)
  27.  
  28.         else:
  29.             print("You have entered a invalid command!")
  30.  
  31.  
  32. class Basement:
  33.     def __init__(self, inventory):
  34.         self.inventory = inventory
  35.  
  36.     @staticmethod
  37.     def room_message():
  38.         print("You have entered the Basement. In front of you there is a blue BMW M3.\n"
  39.               "Behind the car there is big shelf with working equipment.\n"
  40.               "On your right there is a garage door and on your left there is a dirty desk.")
  41.  
  42.     @staticmethod
  43.     def handle_help():
  44.         print("\nHere is a list of actions you make take:\n"
  45.               "\"go to (location)\" - goes to location\n"
  46.               "\"enter (area)\" - enters an area\n"
  47.               "\"take (item)\" - stores an item in your inventory\n"
  48.               "\"drop (item)\" - drops an item from inventory\n"
  49.               "\"leave\" - leaves current location")
  50.  
  51.     @staticmethod
  52.     def handle_desk():
  53.         print("\nYou came to the desk and\n"
  54.               "and you noticed a small drawer.\n"
  55.               "You try to open it but it seems to be stuck.\n"
  56.               "Do you want to apply more force to it? \n"
  57.               "Yes or no?")
  58.         command = input()
  59.         first_room_commands = command.split()
  60.         if first_room_commands[0].lower() == 'yes':
  61.             print('\nYou have opened the drawer but there is\n'
  62.                   'only dust and spider web.\n'
  63.                   'What do you do now?')
  64.         else:
  65.             print("What do you do now?")
  66.         command_array = InputHandler.get_input()
  67.         InputHandler.check_room_input(command_array)
  68.  
  69.     @staticmethod
  70.     def handle_garage_door():
  71.         print("\nYou came to the garage door\n"
  72.               "but it seems to be locked and \n"
  73.               "you can't to anything about it.\n"
  74.               "What do you do now?")
  75.         command_array = InputHandler.get_input()
  76.         InputHandler.check_room_input(command_array)
  77.  
  78.     @staticmethod
  79.     def handle_shelf():
  80.         print("\nYou came to the shelf and\n"
  81.               "you come across a lot of\n"
  82.               "working equipment and repair kits.\n"
  83.               "Looks like the owner of the house is\n"
  84.               "a car mechanic. You notice a car key\n"
  85.               "hanging on the wall.\n"
  86.               "What do you do now ?")
  87.         command = input()
  88.         command_array = command.split()
  89.         if command_array[0].lower() == 'take' and len(command_array) > 1:
  90.             if command_array[1] == 'key':
  91.                 if command_array[1] in inventory:
  92.                     print("\nYou already have that item!\n"
  93.                           "What do you do now?")
  94.                 else:
  95.                     inventory.append(command_array[1])
  96.                     print('\nYou have taken the key and put\n'
  97.                           'it inside your pocket\n'
  98.                           'What do you do now?')
  99.                 command_array = InputHandler.get_input()
  100.                 InputHandler.check_room_input(command_array)
  101.             else:
  102.                 print("\nYou have entered a invalid second statement.\n"
  103.                       "Maybe you meant to write: key")
  104.                 command_array = InputHandler.get_input()
  105.                 InputHandler.check_room_input(command_array)
  106.         else:
  107.             command_array = InputHandler.get_input()
  108.             InputHandler.check_room_input(command_array)
  109.  
  110.     @staticmethod
  111.     def handle_car():
  112.         print("\nYou came to the driver's door of\n"
  113.               "the car. Maybe you want to enter it?\n"
  114.               "What do you do now?")
  115.         command_array = InputHandler.get_input()
  116.         InputHandler.check_room_input(command_array)
  117.  
  118.     @staticmethod
  119.     def handle_go(command_array):
  120.         if len(command_array) < 2:
  121.             print("\nYou didn't enter enough commands.\n"
  122.                   "Please type HELP if you don't know what to type!")
  123.         elif len(command_array) == 2:
  124.             if command_array[1] == 'to':
  125.                     print("\nYou didn't state your destination!\n"
  126.                           "Please state where you want to go!")
  127.             else:
  128.                 print("\nThe correct command is\n"
  129.                       "go to (location)")
  130.  
  131.         elif len(command_array) == 3:
  132.             if command_array[2] == 'desk':
  133.                 Basement.handle_desk()
  134.             elif command_array[2] == 'garage-door':
  135.                 Basement.handle_garage_door()
  136.             elif command_array[2] == 'shelf':
  137.                 Basement.handle_shelf()
  138.             elif command_array[2] == 'car':
  139.                 Basement.handle_car()
  140.             else:
  141.                 print("\nYou have entered a invalid third statement.\n"
  142.                       "Maybe you meant to write: desk\n"
  143.                       "garage-door\n"
  144.                       "shelf\n"
  145.                       "car")
  146.         else:
  147.             print("\nInvalid command! Please type HELP if you don't know the commands!")
  148.  
  149.     @staticmethod
  150.     def handle_drop(command_array):
  151.         if len(command_array) < 2:
  152.             print("\nYou didn't enter enough commands.\n"
  153.                   "Please type HELP if you don't know what to type!")
  154.         elif len(command_array) == 2:
  155.             if command_array[1] == 'key':
  156.                 inventory.remove(command_array[1])
  157.                 print('\nYou have dropped your key.\n'
  158.                       'What do you do now?')
  159.         else:
  160.             print("\nYou have entered a invalid second statement.\n"
  161.                   "Maybe you meant to write: key\n"
  162.                   "keychain")
  163.  
  164.     @staticmethod
  165.     def handle_enter(command_array):
  166.         if len(command_array) < 2:
  167.             print("\nYou didn't enter enough commands.\n"
  168.                   "Please type HELP if you don't know what to type!")
  169.         elif len(command_array) == 2:
  170.             if command_array[1] == 'car':
  171.                 if 'key' in inventory:
  172.                     print("\nYou unlock the doors of the car\n"
  173.                           "and you sit on the driver's seat.\n"
  174.                           "You insert the key in the ignition\n"
  175.                           "and you give it a twist. The radio\n"
  176.                           "begins to play a random song\n"
  177.                           "You can notice the glove compartment\n"
  178.                           "is completely open. Inside you can see\n"
  179.                           "the car's documents and a keychain\n"
  180.                           "What do you do now?")
  181.                     command = input()
  182.                     command_array = command.split()
  183.                     if command_array[0].lower() == 'take' and len(command_array) > 1:
  184.                         if command_array[1] == 'keychain':
  185.                             if command_array[1] in inventory:
  186.                                 print("\nYou already have that item!\n"
  187.                                       "What do you do now?")
  188.                             else:
  189.                                 inventory.append(command_array[1])
  190.                                 print('\nYou have taken the keychain and put\n'
  191.                                       'it inside your pocket\n'
  192.                                       'What do you do now?')
  193.                         else:
  194.                             print("\nYou have entered a invalid second statement.\n"
  195.                                   "Maybe you meant to write: keychain")
  196.                     else:
  197.                         command_array = InputHandler.get_input()
  198.                         InputHandler.check_room_input(command_array)
  199.                 else:
  200.                     print("\nThe car is locked.\n"
  201.                           "What do you do now?")
  202.         else:
  203.             print("\nYou have entered a invalid second statement.\n"
  204.                   "Maybe you meant to write: car\n")
  205.  
  206.  
  207. Basement(inventory).room_message()
  208.  
  209. while True:
  210.     command_array = InputHandler.get_input()
  211.     InputHandler.check_room_input(command_array)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top