Question
I have the following feedback for my code. Can anyone please help me with it? Feedback Please ensure that you've printed all the required information
I have the following feedback for my code. Can anyone please help me with it?
Feedback
Please ensure that you've printed all the required information in the function that displays the game state. This function must be called show_status - and it must display the following details - 1) Which room the player is currently in. 2) What item is present in the room. 3) What items are in the inventory. 4) The directions he can move in from this room. And also remember to call this function from the driver loop that facilitates the gameplay routine. We've seen the work you've put it into this function. Kudos on how far you've come! :) PS. It wouldn't be a bad idea to check a little about how you can print neatly from this manual here - have fun!
-combine or consolidate room dictionaries to ensure there are not conflicts.
-recommended dictionaries have matching keys and values.
-consolidate my print()functions into a custom function which allows for one event to be executed in the event a specific prompt needs to be made in the system.
- 1.) male sure to define a function that takes (direction, current_room) as parameters and returns new state based on the room directory.
2.) then make sure this function is called only once in a driving while loop -once a move has been made.
3.) take care of cases within your function when you're running outside the map.
#Code
# my name
# Function to show game instructions def show_instructions(): print("Text-Based Adventure Game") print("Collect all items to win the game.") print("Move commands: go South, go North, go East, go West") print("Add to Inventory: get 'item name'")
# Function to show player status def show_status(room, inventory): print("Current room:", room) print("Inventory:", inventory)
# Dictionary linking rooms to one another and linking items to rooms rooms = { 'Great Hall': { 'South': 'Bedroom', 'North': 'Dungeon', 'East': 'Kitchen', 'West': 'Library' }, 'Bedroom': { 'North': 'Great Hall', 'East': 'Cellar', 'item': 'Armor' }, 'Cellar': { 'West': 'Bedroom', 'item': 'Helmet' }, 'Dining Room': { 'South': 'Kitchen', 'item': 'Dragon' } }
# Main function def main(): # Initialize player status room = 'Great Hall' inventory = [] # Show game instructions show_instructions() # Start game loop while True: # Show player status show_status(room, inventory) # Get player command move = input("Enter command: ").split() # Check if player wants to move between rooms if move[0] == 'go': if move[1] in rooms[room]: room = rooms[room][move[1]] else: print("Invalid move") # Check if player wants to get an item elif move[0] == 'get': if 'item' in rooms[room]: item = rooms[room]['item'] inventory.append(item) print("You got the", item) del rooms[room]['item'] else: print("No item in this room") # Invalid command else: print("Invalid command")
# Run main function 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