I'm having trouble with an assignment of mine. I'm making a text based adventure game for extra credit in my class and I'm stuck
on where to continue the code. Basically it's a text based adventure game written in PYTHON. Effectively most rooms have an item and the player MUST obtain two of these items (The Magic Sword and Magic Shield) to defeat the lich, if the player does not have these items, then the game gives an instant game over. This is the code I have done so far, it's the going from room to room portion.
#First, all the rooms are set up.
rooms = {
'Entrance': {'East': 'Private Study'},
'Dining Hall': {'South': 'Kitchen', 'North': 'Entrance', 'East': 'Armory', 'West': 'Hidden Room', 'Item': 'Map'},
'Kitchen': {'North': 'Dining Hall', 'East': 'Dungeon', 'Item': 'Food'},
'Dungeon': {'West': 'Kitchen', 'Item' : 'Lich'},
'Old Bedroom': {'South': 'Armory', 'Item': 'Potion'},
'Armory': {'West': 'Dining Hall', 'North': 'Old Bedroom', 'Item': 'Magic Shield'},
'Private Study' : {'West' : 'Entrance', 'Item' : 'Hidden Room Key'},
'Hidden Room' : {'East' : 'Dining Hall', 'Item' : 'Magic Sword'}
}
#Then the starting room is set
room = 'Entrance'
#This definition will set up the function to move betweem rooms.
def move_to_room(room, direct):
new_room = room
for a in rooms:
if a == room:
if direct in rooms[a]:
if isinstance(rooms[a][direct], list): #This if function is set up incase there are ever two paths in a room
b = input()
if b == '1':
new_room = rooms[a][direct][0]
else:
new_room = rooms[a][direct][1]
else:
new_room = rooms[a][direct]
return new_room
#The while loop is the full gameplay loop, the majority in which the player will see.
#First it will display what room the player is currently in, then asks them what they wish to do.
while 1:
print('\nYou have entered', room)
print('If you wish to stop playing, please enter "Stop" or "stop"')
print("Please enter north, south, east, or west please.")
direct = input('\nWhich direction do you want to enter?: ')
#If the player enters stop, then the game stops
if direct == 'Stop' or direct == 'stop':
exit(0)
#The main if for moving between rooms, there is a a there are no paths, then they player cannot move that way
if direct == 'east' or direct == 'west' or direct == 'north' or direct == 'south':
new_room = move_to_room(room, direct)
if new_room == room:
print('There is a wall in your path! Please enter another direction: ')
else:
room = new_room
#Another if incase the player enters with capital letters in their directions
if direct == 'East' or direct == 'West' or direct == 'North' or direct == 'South':
new_room = move_to_room(room, direct)
if new_room == room:
print('There is a wall in your path! Please enter another direction: ')
else:
room = new_room
#If there is an invalid entry that doesn't fit in the rooms, then the player will be told to enter it again.
else:
print('\nINVALID DIRECTION, PLEASE ENTER A VALID OPTION')