I'm crafting an item collecting dungeon game. I have an if
statement that looks at my sorted inventory list and triggers if I have collected all of the items. The next elif
statement triggers if I enter the exit room and don't have all the items. The next elif
statement is supposed to trigger when I have all items and enter the exit room but I cannot get it to work.
def main():
# an empty inventory to be added to as player progresses.
inventory = []
# a dictionary of rooms and items.
rooms = {
'your apartment': {'west': 'occult bookstore', 'south': 'McDally\'s Pub'},
'occult bookstore': {'east': 'your apartment', 'item': 'skull'},
'McDally\'s Pub': {'north': 'your apartment', 'east': 'Shedd Aquarium', 'south': 'Wrigley Field',
'item': 'energy potion'},
'Wrigley Field': {'north': 'McDally\'s Pub', 'west': 'your office', 'item': 'wizard staff'},
'your office': {'east': 'Wrigley Field', 'item': 'Faerie Queen'},
'Shedd Aquarium': {'west': 'McDally\'s Pub', 'north': 'Field Museum of Natural History',
'item': 'enchanted duster'},
'Field Museum of Natural History': {'south': 'Shedd Aquarium', 'north': 'Saint Mary of the Angels church',
'item': 'blasting rod'},
'Saint Mary of the Angels church': {'south': 'Field Museum of Natural History', 'item': 'shield bracelet'}
}
# set start room.
current_room = 'your apartment'
# start_game()
while True:
# sort inventory.
sorted_inv = sorted(inventory)
# display instructions.
instructions()
# establish win condition.
if sorted_inv == ['blasting rod', 'enchanted duster', 'energy potion', 'shield bracelet', 'skull',
'wizard staff']:
print('\nYou\'ve got your stuff back. Time to see the Queen.')
elif current_room == 'your office' and sorted_inv != ['blasting rod', 'enchanted duster', 'energy potion',
'shield bracelet', 'skull', 'wizard staff']:
print('You were unprepared. The Queen tears you head off. Game over.')
break
elif current_room == 'your office' and sorted_inv == ['blasting rod', 'enchanted duster', 'energy potion',
'shield bracelet', 'skull', 'wizard staff']:
print('The Faerie Queen has terrorized your city for the last time.')
break
I'm trying to give you as little code to look through as possible, so let me know if I need to give more.
The problem code is under the while True
statement. The first if
and elif
statements work but the last elif
does not. I've tried making it an else
statement but that also does not trigger. Any help would be greatly appreciated.