Question
Can someone help me complete the code? I tried to include the map for the game. I wrote the move instructions with room titles and
Can someone help me complete the code? I tried to include the map for the game. I wrote the move instructions with room titles and items at the end. Just in case it does not show the map. Below is what I have so far. I really appreciate any help you can provide.
Side note I don't know how to comment on an answered question. I don't see a place to do that.
# 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 = {
'Foyer': {
'East': 'Living room',
'North': 'Study',
'South': 'Kitchen',
'West': 'Office',
'West': 'Bedroom'
}
# Main function
def main():
# Initialize player status
room = ''
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()
#Start=Foyer
East to the living room with a flashlight
North to study with First aid kit
East to Master bedroom with power-up item
West to return to the Study
South back to the living room
South to the kitchen with Flammable aerosol spray
East to Bedroom with lighter
West to return to the Kitchen
North to return to the living room
East to the office with a key to exit monsters lair
North to Basement with Monster
Defeat the monster use the key to exit
End
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