Untitled
unknown
plain_text
4 years ago
1.5 kB
14
Indexable
# write your name here
# function to print instructions to the user
def game_instructions():
print('\nWelcome to the Moving Between Rooms game')
print('Move Commands: go North, go South, go West, go East')
print('Type quit to end game.')
# function to move between rooms
def move_between_rooms(current_room, move, rooms):
current_room = rooms[current_room][move]
return current_room
# dictionary storing map of rooms
rooms = {
'Great Hall': {'South': 'Bedroom'},
'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'},
'Cellar': {'West': 'Bedroom'}
}
# current location of the player
current_room = 'Great Hall'
game_instructions()
# loop to start playing
while current_room != 'exit':
# printing current position of player
print('You are in the ' + current_room)
print('---------------------------')
# taking input from user
move = input('Enter your move: ').title().split()
# using if else conditions to dictate the player's moves
if len(move) >= 2 and move[0].lower() == 'go' and move[1].capitalize() in rooms[current_room].keys():
current_room = move_between_rooms(current_room, move[1].capitalize(), rooms)
continue
elif len(move) == 1 and move[0].lower() == 'exit':
current_room = 'exit'
print('Thanks for playing!')
else:
# incase user inputs wrong moves
print('Invalid move !!')
print('Please try again!!')Editor is loading...