I'm taking a scripting class and we are working in python. My final project is a text based game and I'm having trouble figuring out how I can make only one item show up, depending on which room the user is in, out of a list of items. I've made a function to allow the user to add the item to the inventory, but I can only make 1 item show up in each room, or all items show up in each room.
rooms = {
'Your bedroom': {
'north': 'Alley Way'
},
'Alley Way': {
'north': 'Main Hall',
'east': 'Bar',
'west': 'Ammo Store',
'south': 'Your bedroom',
'item': 'Cloaking Device'
},
'Bar': {
'west': 'Alley Way'
},
'Ammo Store': {
'east': 'Alley Way',
'item': 'Gun'
},
'Main Hall': {
'north': 'Oval Office',
'west': 'West Wing',
'east': 'East Wing',
'south': 'Alley Way'
},
'East Wing': {
'west': 'Main Hall'
},
'West Wing': {
'east': 'Main Hall'
},
'Oval Office': {
'south': 'Main Hall'
}
}
items = ['Cloaking Device', 'Whiskey', 'Gun', 'Noise Maker', 'Key', 'Rocket Launcher']
def player_stat():
print("-" * 20)
print('You are in the {}'.format(location))
print('You have {} in your inventory.'.format(inventory))
print("-" * 20)
def get_item():
command = input('Would you like to pick up the {}?').format(items).strip().lower()
if command == 'yes':
inventory.append(items)
print('{} has been added to your inventory'.format(items))
location = 'Your bedroom'
item = 'item'
inventory = []
direction = ''
while direction != 'exit':
if location == 'Your bedroom':
print('\nYou are currently in', location)
possible_moves = rooms[location].keys()
print('You can move:', *possible_moves)
direction = input('What will yor next move be? ').strip().lower()
print('You entered:', direction)
if direction in rooms[location]:
location = rooms[location][direction]
if location == 'Alley Way':
player_stat()
print('You have left your room and entered the Alley Way.', '\n'
'You notice some alien guards roughing up a homeless man.', '\n'
'While wrangling the homeless man, you notice one of the guards drop their cloaking device.')
if item:
print('You see a {}'.format(items[0]))
get_item()
input('Would you like to pick up the {}?').format(items) is where I am trying to select only the item that should be in each room, but I just can't seem to figure out how.