Question
For some reason I cannot get this game to work. Can someone please take a look at it and tell me what I am not
For some reason I cannot get this game to work. Can someone please take a look at it and tell me what I am not doing right?
def show_instructions(): # print a main menu and the commands print(' Fraternity Brothers Super Bowl Text Game') print('Collect all of the necessary items needed to tango with your mother-n-law') print('Commands: go south, go north, go east, go west') print('get book, get armor, get helmet, get keys, get ear plugs, get protein shake') def show_status(current_room, inventory, rooms):
# prints the player's current status print(' ---------------------------') print('You are in the ' + current_room) print('Inventory : ' + str(inventory))
# Prints the item that is in the room if "item" in rooms[current_room]: print('You see a ' + rooms[current_room]['item']) def main():
# Initial inventory, starts out empty inventory = []
# Dictionary linking all of the rooms rooms = { 'Family Room': {'South': 'Bedroom', 'North': 'Garage', 'East': 'Kitchen', 'West': 'Study'}, 'Bedroom': {'North': 'Family room', 'East': 'Man Cave', 'item': 'armor'}, 'Man Cave': {'West': 'Bedroom', 'item': ' helmet'}, 'Garage': {'South': 'Family Room', 'East': 'Tool Shed', 'item': 'ear plugs'}, 'Tool Shed': {'West': 'Garage', 'item': 'keys'}, 'Kitchen': {'West': 'Family Room', 'North': 'Living Room', 'item': 'protein shake'}, 'Living Room': {'South': 'Kitchen', 'item': 'mother-n-law'}, 'Study': {'East': 'Family Room', 'item': 'book'} } # Player begins in the Family Room current_room = 'Family Room' show_instructions()
while True: show_status(current_room, inventory, rooms) if "item" in rooms[current_room]: if rooms[current_room]['item'] == 'Mother-N-Law': print("I AM NOT GOING ANYWHERE!") break
if len(inventory) == 6: print("Congratulations! You have defeated your mother-n-law!") break print(" ---------------------------") print("Enter your move: ") move = '' while move == '': move = input('>') move = move.split() if len(move) != 2: print("Invalid Input!") continue
if move[0] == 'go' and move[1] in rooms[current_room]: current_room = rooms[current_room][move[1]] print('You can''t go that way!') if move[0] == 'get': if "item" in rooms[current_room] and move[1] in rooms[current_room]['item']: inventory += [move[1]] print(move[1] + ' got!') del rooms[current_room]['item']
else: print('Can''t get' + move[1] + '!')
else: print("Invalid move!") print("Thanks for playing. Hope you enjoyed it.")
if __name__ == '__main__': main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started