Question: I need help finishing this game in Python . Below is the code I already have that allows the player to move between rooms. I
I need help finishing this game in Python. Below is the code I already have that allows the player to move between rooms. I need the code that will allow player to pick up items from the rooms. This is an all text based game.
Other requirements:
- Show the players status by identifying the room they are currently in, showing a list of their inventory of items, and displaying the item in their current room.
- The gameplay loop should continue looping, allowing the player to move to different rooms and acquire items until the player has either won or lost the game. Remember that the player wins the game by retrieving all of the items before encountering the room with the villain. The player loses the game by moving to the room with the villain before collecting all of the items. Be sure to include output to the player for both possible scenarios: winning and losing the game.
- See the flowchart below to see the map of the rooms and the items that need to be in each room.
#The dictionary links a room to other rooms. rooms = { 'Living Room': {'West': 'Garage', 'North': 'Kids Room', 'East': 'Kitchen','South': 'Loft'}, 'Kids Room': {'South': 'Living Room', 'East': 'Bathroom'}, 'Bathroom': {'West': 'Kids Room'}, 'Garage': {'East': 'Living Room'}, 'Loft': {'North': 'Living Room', 'East': 'Game Room'}, 'Game Room': {'West': 'Loft'}, 'Kitchen': {'North': 'Master Bedroom', 'West': 'Living Room'}, 'Master Bedroom': {'South': 'Kitchen'}, } room = 'Living Room' def get_new_room(room, direction): #creating room function new_room = room #setting new_room equal to room for i in rooms: #creating a loop to check for i in rooms if i == room: #if room matches entry in dictionary rooms if direction in rooms[i]: #if the direction the player wants to move matches the entry in the rooms dictionary new_room = rooms[i][direction] #setting new_room equal to the moved to room return new_room #return the desired value for when this function is called while (1): #movement loop print('You are in ', room) #telling the player where they are direction = input('Enter which direction you want to go or enter exit: ') #ask user where they want to go direction = direction.capitalize() #account for capitalization discrepencies if (direction == 'Exit'): #giving the user a way to exit the game exit(0) #exiting the game if (direction == 'East' or direction == 'West' or direction == 'North' or direction == 'South'): #if statement based on desired direction new_room = get_new_room(room, direction) #call on the get_new_room function if new_room == room: #create output based on invalid move print('That is not a valid direction!') #tell the player that is an invalid move else: room = new_room #set room equal to new_room else: print('That is not a valid direction!') #tell the player that is an invalid move
East Kids Room Bathroom Item: dynamite Item: hammer living room, kids rooms, kitchen, bathroom, garage, master bedroom, loft, and game room West North South cheese, mousetrap, hammer, dynamite, anvil, and super glue Master Bedroom Villain Lair (lose game if you come here) East Garage Living Room Item: super glue North South (Start room, no items) West East Kitchen Item: cheese West North South East Loft Game Room Item: anvil Item: mousetrap West
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
