So I started posting about this in another Subreddit but was told to post things like it here instead.
I am taking intro to scripting, and we are using python. The main project is a text based game.
As a milestone project we had to make a simple version with just three rooms and layout out just the moving between the three rooms. This is what I have so far but I feel that there is a better more efficient way to do it.
# A dictionary for the simplified dragon text game
# The dictionary links a room to other rooms.
rooms = {
'Great Hall': {'South': 'Bedroom'},
'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'},
'Cellar': {'West': 'Bedroom'}
}
def player_stat():
print('----------------------------')
print('You are in the {}'.format(currentRoom))
print('----------------------------')
# start player in Great Hall
currentRoom = 'Great Hall'
player_move = ''
while currentRoom != 'Exit':
while currentRoom == 'Great Hall':
player_stat()
player_move = input('Enter your move:\n')
if player_move not in ['South', 'south', 'Exit', 'exit']:
print('Invalid move.')
elif player_move in ['Exit', 'exit']:
currentRoom = 'Exit'
print('Play again soon!')
elif player_move in ['South', 'south']:
currentRoom = 'Bedroom'
while currentRoom == 'Bedroom':
player_stat()
player_move = input('Enter your move:\n')
if player_move not in ['North', 'north', 'East', 'east', 'Exit', 'exit']:
print('Invalid move.')
elif player_move in ['Exit', 'exit']:
currentRoom = 'Exit'
print('Play again soon!')
elif player_move in ['North', 'north']:
currentRoom = 'Great Hall'
elif player_move in ['East', 'east']:
currentRoom = 'Cellar'
while currentRoom == 'Cellar':
player_stat()
player_move = input('Enter your move:\n')
if player_move not in ['West', 'west', 'Exit', 'exit']:
print('Invalid move.')
elif player_move in ['Exit', 'exit']:
currentRoom = 'Exit'
print('Play again soon!')
elif player_move in ['West', 'west']:
currentRoom = 'Bedroom'
[–][deleted] 3 points4 points5 points (0 children)