I am writing this for a class. I keep running issues with being able to validate if a person is typing 'Go' or 'Get'. If i type 'bo north', the code will execute to the next room. It should give an error code. I also think my def move_directions can be shortened but I am having trouble with anything to work. I tried adding directions as a list and use that, but that didn't work. I was trying to get player input to some how match with the direction and then move rooms by rooms[current_rooms][direction].
Very new to this and not fully understanding the best practices yet. Such as what the name in main func does and if I could use it???
Any help is appreciated.
# Sample function showing the goal of the game and move commands
def show_instructions():
# print a main menu and the commands
print("Santa's Great Escape Adventure Game")
print("Collect 6 items to win the game, or get caught by the family dog, Snarls Bite-ley.")
print("Move commands: go South, go North, go East, go West")
print("Add to Inventory: get 'item name'")
def player_stat(current_room, inventory, rooms):
print('--------------------------------------------------------')
print('You are in the {}.'.format(current_room))
print('Inventory:', inventory)
i = len(inventory)
inventory_count = 6 - int(i)
print('Items Left: {} more'.format(inventory_count))
if current_room != 'Living Room':
print('You see the', rooms[current_room]['item'], end='.\n')
print('--------------------------------------------------------')
# A dictionary linking a room to other rooms
# and linking one item for each room except the Start room (Living) and the room containing the villain
def main():
rooms = {
'Living Room': {'South': "Kids' Bedroom", 'North': 'Office', 'East': 'Dining Room', 'West': 'Master Suite'},
'Master Suite': {'East': 'Living Room', 'item': 'Christmas Bell'},
"Kids' Bedroom": {'East': 'Playroom', 'North': 'Living Room', 'item': 'Magic Dust'},
'Playroom': {'West': "Kids' Bedroom", 'item': 'Dog Bone'},
'Dining Room': {'West': 'Living Room', 'North': 'Kitchen', 'item': 'Cookies'},
'Kitchen': {'South': 'Dining Room', 'item': 'Elf On The Shelf'},
'Office': {'South': 'Living Room', 'East': 'Bonus Room', 'item': 'Dog Blankie'},
'Bonus Room': {'West': 'Office', 'item': 'Snarls Bite-ley'} # Villain
}
current_room = 'Living Room'
player_move = ''
inventory = []
show_instructions()
def move_directions(player_move, current_room):
if player_move == 'South':
return rooms[current_room]['South']
elif player_move == 'North':
return rooms[current_room]['North']
elif player_move == 'East':
return rooms[current_room]['East']
elif player_move == 'West':
return rooms[current_room]['West']
def get_item():
if player_move in rooms[current_room]['item']:
inventory.append(rooms[current_room]['item'])
while True:
while len(inventory) <= 6 and current_room != 'Bonus Room':
player_stat(current_room, inventory, rooms)
if len(inventory) == 6 and current_room == 'Bonus Room':
print("You give Snarls Bite-ly his bone and blanket and escape the out the Bonus Room window.")
print("YOU WIN!")
print("MERRY CHRISTMAS!")
user_input = input('Enter your move:\n').title().split()
print(user_input[0])
if user_input[0] == 'Go' or 'Get':
user_input.pop(0)
player_move = ' '.join([str(elem) for elem in user_input])
print(player_move) # used for testing of split REMOVE LATER
if player_move == 'Exit':
exit('You have exited the game. Play again soon!')
# Prints when game exited, ends game
# Game play loop to validate moves.
elif player_move in rooms[current_room]:
current_room = move_directions(player_move, current_room)
# need to validate items and add to inventory if not in inventory
elif player_move in rooms[current_room]['item']:
if player_move in inventory:
print('**You already have this item. Proceed to another room.**')
elif player_move != inventory:
get_item()
elif user_input[0] != 'Go' or 'Get':
print("That is not a valid move. Try again.")
else:
print("That is not a valid move. Try again.") # Display if invalid move
quit('******** Snarls Bite-ley AWAKES! ********\n'
'You are Trapped and the Family AWAKES!\n'
'************ G A M E O V E R ************')
break
main()