So far I have been able to add either one-word values or 2-word values but not both. For example, I want to go to one location and add a skull to my inventory, then move to another location and add an energy potion to my inventory. With my current code, I can add the energy potion by using .split(maxsplit=1)
or .split(' ', 1)
. That was to solve the issue of not being able to add a value with 2 words. But this seems to prevent adding values with one word to the inventory.
while True:
instructions()
player_status(rooms, current_room, inventory)
time.sleep(0.5)
# sets up user command to move player between rooms.
command = input('\nWhat do you want to do?\n>').title().strip()
if command in rooms[current_room]:
current_room = rooms[current_room][command]
time.sleep(0.5)
# command to add item to inventory and remove it from dict.
elif command.lower().split()[0] == 'get':
obj = command.lower().split(maxsplit=1)[1]
if obj in rooms[current_room]['item']:
del rooms[current_room]['item']
inventory.append(obj)
else:
print("I don't see that here.")
# a command to quit the game.
elif command.lower() in ('q', 'quit'):
time.sleep(0.5)
print('\nThanks for playing.')
break
# if player inputs an invalid command.
else:
time.sleep(0.5)
print('\nYou can\'t go that way!')
Here is an example of the output:
You are at occult bookstore.
There is a Skull
You have: ['energy potion']
What do you want to do?
>get skull
I don't see that here.