I am creating a text based adventure game for one of my college courses. I need to be able to move through the rooms, pick up all the items, and get to the 'Boss' room to finish the game. It is not finished, but so far I was able to make movement throughout the game with ease, however I am unable to pick up items in the spaces.
My Code:
rooms = { # create dictionary with list of rooms
'Center of the Village': {'go north': "Village Scribe", 'go south': "Mage Tower", 'go east': 'Village Dining Hall', 'go west': "Village Tailor', 'item': 'None'"},
'Village Scribe': {'go east': 'Bridge to the Castle', 'go south': 'Center of the Village', 'item': 'Monster Hunting Guidebook'},
'Mage Tower': {'go north': 'Center of the Village', 'go east': 'Mage Library', 'item': 'Magic Staff'},
'Village Dining Hall': {'go north': 'Village Elders', 'go west': 'Center of the Village', 'item': 'Hearty Stew'},
'Village Tailor': {'go east': 'Center of the Village', 'item': 'Magic Cloak'},
'Village Elders': {'go south': 'Village Dining Hall', 'item': 'Amulet of Protection'},
'Mage Library': {'go west': 'Mage Tower', 'item': 'Spell Caster Scrolls'},
'Bridge to the Castle': {'go west': 'Village Scribe', 'boss': 'Bridge Troll'}
}
def main_menu(): # create main menu prompt when game is launched
print('---------------------------')
print("Magicians Adventure Text Game\n")
print("Movement Commands: "
"\nType: 'go' Followed by: 'north', 'south', 'east', or 'west' to move through the village. "
"\nType: 'get' to pick up an item. "
"\nType: 'exit' to end the game.")
input('\nPress Enter to continue...\n---------------------------\n')
return "Good Luck!"
def show_status(): # indicate room and inventory contents
print('\n-------------------------')
print('You are in the {}'.format(current_room))
print('In this room you see a {}'.format(rooms[current_room]['item']))
print('Inventory:', inventory)
print('-------------------------------')
print(main_menu()) # print main menu for player
print()
current_room = 'Center of the Village' # starting room for player
commands = ['go north', 'go south', 'go east', 'go west', 'exit', 'get'] # valid movements
inventory = []
item = rooms[current_room].get('item')
def move_rooms(current_room, directions): # define the movement sequence between rooms
current_room = rooms[current_room]
new_room = current_room[directions]
return new_room # use return function to apply new location
while True:
show_status()
direction_input = input('What direction would you like to travel? \n \n> ')
print('--------------------------')
moves = rooms[current_room]
if direction_input == 'exit': # use if statement with exit as key input and break
print('Thanks for playing!')
print('---------------------------')
break
else: # add in the below if and elifs for valid and not valid moves from the player
if direction_input in rooms[current_room]:
current_room = move_rooms(current_room, direction_input)
elif direction_input not in commands:
print('Invalid move.\n')
print('---------------------------\n')
elif direction_input not in rooms[current_room]:
print(f'You can not go that way.')
print('---------------------------\n')
elif direction_input == 'get' + rooms[current_room]['item']:
if rooms[current_room]['item'] not in inventory:
inventory.append(rooms[current_room]['item'])
else:
print('You have already picked this item up.\n')