I am supposed to write a program for a simple text-based game. You have to move from one room to the next. The map starts in the Observation room and you can go south to the Rec room or exit the game. From the Rec room you can go north back to the Observation room, exit or you can go east to the Lab. From the Lab you can go west back to the Rec room or exit.
I need to display game instructions, display the room the player is in each time they move, and if they want to exit an exit message displays and game ends.
player_name = input('Enter your name Captain:')
def game_play_instructions():
# print a main menu and the commands
print('-----------------------------------------------------------------------------------')
print("Hello, Captain", player_name, '!')
print("You will need to navigate around the spaceship to get familiar with your surrounds.")
print("Move commands: go South, go North, go East, go West")
print('Type Exit to end the game at anytime.')
print('-----------------------------------------------------------------------------------')
game_play_instructions()
current_room = 'Observation Room'
rooms = {
'Observation Room': {'South': 'Rec Room'},
'Rec Room': {'East': 'Lab', 'North': 'Observation Room'},
"Lab": {"West": "Rec Room"}
}
directions = ['North', 'South', 'East', 'West', 'exit']
room = rooms['Observation Room']
while True:
print()
print('You are in the', room, '.')
user_move = input('What would you like to do?')
if user_move in directions:
if user_move in room:
room = rooms[room[user_move]]
else:
print('Invalid input, I do not understand!')
# function
def get_new_room(room, user_move):
new_room = room # declaring
for i in rooms: # loop
if i == room: # if
if user_move in rooms[i]: # if
new_room = rooms[i][user_move] # assigning new_state
return new_room # return
print()
game_play_instructions() # calling function
user_move = input('What would you like to do? ') # asking user
direction = input(user_move)
while direction != 'exit':
direction = input(user_move)
if user_move == 'go East' or user_move == 'go West' or user_move == 'go North' or user_move == 'go South': # if
user_move = user_move[3:]
new_room = get_new_room(room, user_move) # calling function
if new_room == room: # if
print('There is no passage that way, choose a different direction.') # print
else:
room = new_room # changing state value to new_state
else:
print('Invalid direction!!') # print
When I run my program this is what I get:
Enter your name Captain:CP
-----------------------------------------------------------------------------------
Hello, Captain CP !
You will need to navigate around the spaceship to get familiar with your surrounds.
Move commands: go South, go North, go East, go West
Type Exit to end the game at anytime.
-----------------------------------------------------------------------------------
You are in the {'South': 'Rec Room'} .
(PROGRAM SHOULD START IN OBSERVATION ROOM and room should update depending on the direction the player wants to go)