When i enter a room, i am prompted with an item to be picked up and added to my inventory, when i enter a room with a one word item, i can pick it up no problem, but when i go into a room with a two word item, i cannot pick it up and add it to my inventory. I feel like i'm missing something obvious, but i can't figure it out, i've been on this for a while and finally have folded and am asking for help.
def display_instructions():
print("++++++++++++++++++++")
print("You are a village witch doctor and an villager is sick. "
"Collect the ingredients for a potion to cure the sick villager")
print("++++++++++++++++++++")
print("Use go North, go South, go East, go South to navigate "
"different sections of the forest. Use get, with item name after to pick up item.")
print("++++++++++++++++++++")
def display_room(room, items):
print("You are in the " + room + ".")
if len(items) > 0:
print("In this room, you see the following items: ")
for item in items:
print("- " + item)
else:
print("There are no items in this room.")
print("++++++++++++++++++++")
def display_inventory(inventory):
if len(inventory) > 0:
print("Your inventory contains the following items: ")
for item in inventory:
print("- " + item)
else:
print("Your inventory is empty.")
def get_input():
return input("What would you like to do? ")
def play_game():
rooms = {
"House": {"North": "North Forest", "South": "South Forest"},
"North Forest": {"East": "NE Forest", "South": "House"},
"NE Forest": {"East": "North River", "West": "North Forest"},
"North River": {"South": "Central River", "West": "NE Forest"},
"Central River": {"South": "South River", "North": "North River"},
"South River": {"North": "Central River", "West": "SE Forest"},
"SE Forest": {"West": "South Forest", "East": "South River"},
"South Forest": {"North": "House", "East": "SE Forest"}
}
items = {
"Lilyroot": "North River",
"Pinecone": "North Forest",
"Nest Wax": "NE Forest",
"Feather": "South Forest",
"Green Mushroom": "South River",
"Bee Nectar": "SE Forest"
}
current_room = "House"
inventory = []
display_instructions()
while True:
display_room(current_room, [item for item, room in items.items() if room == current_room])
display_inventory(inventory)
user_input = get_input()
command_parts = user_input.lower().split()
if command_parts[0] == "go":
if len(command_parts) == 2:
direction = command_parts[1].capitalize()
if direction in rooms[current_room]:
current_room = rooms[current_room][direction]
else:
print("Invalid Direction.")
print("++++++++++++++++++++")
else:
print("Invalid command. Please enter 'go [direction]'.")
# Here
elif command_parts[0] == "get":
if len(command_parts) == 2:
item_name = command_parts[1].capitalize()
elif len(command_parts) == 3:
item_name = command_parts[2].capitalize()
if item_name in items and items[item_name] == current_room:
inventory.append(item_name)
print("You got " + item_name + "!")
del items[item_name]
else:
print("Incorrect Item Name")
else:
print("Invalid command. Please enter 'get [item name]'.")
else:
print("Invalid command. Please enter 'go [direction]' or 'get [item name]'.")
if current_room == "House" and (len(items) == 0):
print("The potion can now be crafted, the villager is saved!!!!")
if __name__ == "__main__":
play_game()