print(rand.current_room.name) print(rand.current_room.description) if rand.current_room.obstacle: print(f"There is a {rand.current_room.obstacle[0]} in the way") if rand.current_room.inventory: print('Items available:') for i in rand.current_room.inventory: print(i) print('') what = input('What do? ') if len(what) == 1: if what == 'n' or what == 'e' or what == 's' or what == 'w': if not rand.current_room.obstacle: if what == 'n': try: rand.current_room = rand.current_room.n_to except: print('Direction unavailable') elif what == 'e': try: rand.current_room = rand.current_room.e_to except: print('Direction unavailable') elif what == 's': try: rand.current_room = rand.current_room.s_to except: print('Direction unavailable') elif what == 'w': try: rand.current_room = rand.current_room.w_to
# * Prints the current description (the textwrap module might be useful here). # * Waits for user input and decides what to do. # # If the user enters a cardinal direction, attempt to move to the room there. # Print an error message if the movement isn't allowed. # # If the user enters "q", quit the game. while True: command = input("Enter a command: ") if command == 'q': exit(1) if command == 'n': if player.current_room.n_to is not None: player.current_room = player.current_room.n_to print(player.current_room.__str__()) else: print("Error: there is nothing in that direction") elif command == 'e': if player.current_room.e_to is not None: player.current_room = player.current_room.e_to print(player.current_room.__str__()) else: print("Error: there is nothing in that direction") elif command == 's': if player.current_room.s_to is not None: player.current_room = player.current_room.s_to print(player.current_room.__str__())
if len(new_player.current_room.items) > 0: print(f"\nThese are the items in this room:") for i in new_player.current_room.items: print(f"\t- {i.name}") user_input = input("\nWhat would you like to do? ") action = user_input.lower() action_split = action.split() if len(action_split) == 1: if action == "q": print(f"\n{new_player.name}, thank you for playing. Goodbye!") break elif action == "n": if new_player.current_room.n_to is not None: new_player.current_room = new_player.current_room.n_to else: print("\nI'm sorry! That move is not possible.") elif action == "e": if new_player.current_room.e_to is not None: new_player.current_room = new_player.current_room.e_to else: print("\nI'm sorry! That move is not possible.") elif action == "w": if new_player.current_room.w_to is not None: new_player.current_room = new_player.current_room.w_to else: print("\nI'm sorry! That move is not possible.") elif action == "s": if new_player.current_room.s_to is not None: new_player.current_room = new_player.current_room.s_to