Search code examples
pythoninventoryadventure

How to add inventory to the current script


So thanks to another person here I got the movement working but now I'm not sure how to incorporate the items I put into the dictionary into a way where the player can see that the item is in the room and can get it. Or check the final room that has the boss. if they get to the final room before having all 6 items then they die! Here is the code and how would I go about doing it?

#define inventory and dictionary linking other rooms
rooms = {

    'Entry Way': { 'North': 'Stalagmite Cavern'},
    'Stalagmite Cavern': {'North': 'Grand Cavern', 'South': 'Entry Way', 'item': 'torch'},
    'Grand Cavern': {'North': 'Hallway', 'East': 'Armory', 'West': 'Bedroom', 'South': 'Stalagmite Cavern', 'item': 'cross'},
    'Armory': {'North': 'Treasure Trove', 'West': 'Grand Cavern', 'item': 'Stake'},
    'Treasure Trove': {'South': 'Armory', 'item': 'silver'},
    'Bedroom': {'North': 'Storage', 'East': 'Grand Cavern', 'item': 'elaborate comb'},
    'Storage': {'South': 'Bedroom', 'item': 'mirror'},
    'Hallway': {'North': 'Cliff Top', 'South': 'Grand Cavern'},
    'Cliff Top': {'South': 'Hallway', 'item': 'Orla'}
}

def show_instructions():
   #print a main menu and the commands
   print("Thousand Year Vampire")
   print("Collect 6 items to defeat the vampire or be destroyed by her.")
   print("Move commands: go South, go North, go East, go West")
   print("Add to Inventory: get 'item name'")

def show_status():
    print(current_room)
    print(inventory)
    #print the player's current location
    #print the current inventory
    #print an item if there is one

# setting up inventory
inventory = []

# setting the starting room
starting_room = 'Entry Way'

# set current room to starting room
current_room = starting_room

#show game instructions
show_instructions()

show_status()

while True:
    print("\nYou are currently in the {}".format(current_room))
    move = input("\n>> ").split()[-1].capitalize()
    print('-----------------------------')

    # user to exit
    if move == 'Exit':
        current_room = 'exit'
        break

    # a correct move
    elif move in rooms[current_room]:
        current_room = rooms[current_room][move]
        print('inventory:', inventory)

    # incorrect move
    else:
        print("You can't go that way. There is nothing to the {}".format(move))

#loop forever until meet boss or gets all items and wins

Solution

  • i think you just need to browse the dic like this:

    def get_item():
        for keys in rooms[current_room]:
            if(keys=='item'):
                inventory.append(rooms[current_room][keys])