Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inventory = []
- class InputHandler:
- @staticmethod
- def get_input():
- command = input()
- command_array = command.split()
- return command_array
- @staticmethod
- def check_room_input(command_array):
- if command_array[0] == 'go':
- Basement.handle_go(command_array)
- elif command_array[0] == 'enter':
- Basement.handle_enter(command_array)
- elif command_array[0] == 'take':
- return True
- elif command_array[0] == 'drop':
- Basement.handle_drop(command_array)
- elif command_array[0].lower() == 'help':
- Basement.handle_help()
- return True
- elif command_array[0] == 'inventory':
- print(inventory)
- else:
- print("You have entered a invalid command!")
- class Basement:
- def __init__(self, inventory):
- self.inventory = inventory
- @staticmethod
- def room_message():
- print("You have entered the Basement. In front of you there is a blue BMW M3.\n"
- "Behind the car there is big shelf with working equipment.\n"
- "On your right there is a garage door and on your left there is a dirty desk.")
- @staticmethod
- def handle_help():
- print("\nHere is a list of actions you make take:\n"
- "\"go to (location)\" - goes to location\n"
- "\"enter (area)\" - enters an area\n"
- "\"take (item)\" - stores an item in your inventory\n"
- "\"drop (item)\" - drops an item from inventory\n"
- "\"leave\" - leaves current location")
- @staticmethod
- def handle_desk():
- print("\nYou came to the desk and\n"
- "and you noticed a small drawer.\n"
- "You try to open it but it seems to be stuck.\n"
- "Do you want to apply more force to it? \n"
- "Yes or no?")
- command = input()
- first_room_commands = command.split()
- if first_room_commands[0].lower() == 'yes':
- print('\nYou have opened the drawer but there is\n'
- 'only dust and spider web.\n'
- 'What do you do now?')
- else:
- print("What do you do now?")
- command_array = InputHandler.get_input()
- InputHandler.check_room_input(command_array)
- @staticmethod
- def handle_garage_door():
- print("\nYou came to the garage door\n"
- "but it seems to be locked and \n"
- "you can't to anything about it.\n"
- "What do you do now?")
- command_array = InputHandler.get_input()
- InputHandler.check_room_input(command_array)
- @staticmethod
- def handle_shelf():
- print("\nYou came to the shelf and\n"
- "you come across a lot of\n"
- "working equipment and repair kits.\n"
- "Looks like the owner of the house is\n"
- "a car mechanic. You notice a car key\n"
- "hanging on the wall.\n"
- "What do you do now ?")
- command = input()
- command_array = command.split()
- if command_array[0].lower() == 'take' and len(command_array) > 1:
- if command_array[1] == 'key':
- if command_array[1] in inventory:
- print("\nYou already have that item!\n"
- "What do you do now?")
- else:
- inventory.append(command_array[1])
- print('\nYou have taken the key and put\n'
- 'it inside your pocket\n'
- 'What do you do now?')
- command_array = InputHandler.get_input()
- InputHandler.check_room_input(command_array)
- else:
- print("\nYou have entered a invalid second statement.\n"
- "Maybe you meant to write: key")
- command_array = InputHandler.get_input()
- InputHandler.check_room_input(command_array)
- else:
- command_array = InputHandler.get_input()
- InputHandler.check_room_input(command_array)
- @staticmethod
- def handle_car():
- print("\nYou came to the driver's door of\n"
- "the car. Maybe you want to enter it?\n"
- "What do you do now?")
- command_array = InputHandler.get_input()
- InputHandler.check_room_input(command_array)
- @staticmethod
- def handle_go(command_array):
- if len(command_array) < 2:
- print("\nYou didn't enter enough commands.\n"
- "Please type HELP if you don't know what to type!")
- elif len(command_array) == 2:
- if command_array[1] == 'to':
- print("\nYou didn't state your destination!\n"
- "Please state where you want to go!")
- else:
- print("\nThe correct command is\n"
- "go to (location)")
- elif len(command_array) == 3:
- if command_array[2] == 'desk':
- Basement.handle_desk()
- elif command_array[2] == 'garage-door':
- Basement.handle_garage_door()
- elif command_array[2] == 'shelf':
- Basement.handle_shelf()
- elif command_array[2] == 'car':
- Basement.handle_car()
- else:
- print("\nYou have entered a invalid third statement.\n"
- "Maybe you meant to write: desk\n"
- "garage-door\n"
- "shelf\n"
- "car")
- else:
- print("\nInvalid command! Please type HELP if you don't know the commands!")
- @staticmethod
- def handle_drop(command_array):
- if len(command_array) < 2:
- print("\nYou didn't enter enough commands.\n"
- "Please type HELP if you don't know what to type!")
- elif len(command_array) == 2:
- if command_array[1] == 'key':
- inventory.remove(command_array[1])
- print('\nYou have dropped your key.\n'
- 'What do you do now?')
- else:
- print("\nYou have entered a invalid second statement.\n"
- "Maybe you meant to write: key\n"
- "keychain")
- @staticmethod
- def handle_enter(command_array):
- if len(command_array) < 2:
- print("\nYou didn't enter enough commands.\n"
- "Please type HELP if you don't know what to type!")
- elif len(command_array) == 2:
- if command_array[1] == 'car':
- if 'key' in inventory:
- print("\nYou unlock the doors of the car\n"
- "and you sit on the driver's seat.\n"
- "You insert the key in the ignition\n"
- "and you give it a twist. The radio\n"
- "begins to play a random song\n"
- "You can notice the glove compartment\n"
- "is completely open. Inside you can see\n"
- "the car's documents and a keychain\n"
- "What do you do now?")
- command = input()
- command_array = command.split()
- if command_array[0].lower() == 'take' and len(command_array) > 1:
- if command_array[1] == 'keychain':
- if command_array[1] in inventory:
- print("\nYou already have that item!\n"
- "What do you do now?")
- else:
- inventory.append(command_array[1])
- print('\nYou have taken the keychain and put\n'
- 'it inside your pocket\n'
- 'What do you do now?')
- else:
- print("\nYou have entered a invalid second statement.\n"
- "Maybe you meant to write: keychain")
- else:
- command_array = InputHandler.get_input()
- InputHandler.check_room_input(command_array)
- else:
- print("\nThe car is locked.\n"
- "What do you do now?")
- else:
- print("\nYou have entered a invalid second statement.\n"
- "Maybe you meant to write: car\n")
- Basement(inventory).room_message()
- while True:
- command_array = InputHandler.get_input()
- InputHandler.check_room_input(command_array)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement