Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My code isn't working. My rooms still don t connect, I ve tried multiple times too and it doesn t work. For example, you start

My code isn't working. My rooms still dont connect, Ive tried multiple times too and it doesnt work. For example, you start out in the living room and go up north to the hallway then east to the kitchen but then when you try to go east to the pantry it doesnt. There seem to be lots of bugs like you start out in the living room and go south but the new room desc doesnt print either. Also so make it so the input can handle north south west east as well as n e s w for input. When you start your game, it also doesnt print a room desc either which it should do as how would the player know where they are. Please do multiple test runs to make sure each room works because Ive seen people fix one thing and then break another thing!! Thank you Ive pasted the code below.
# Creating the empty room list
room_list =[]
# Creating rooms
# Format: [Description, North, East, South, West]
# Living Room
room =["You are in a major modern living room. You can go either north or south", 2, None, 1, None]
room_list.append(room)
# Dining Room
room =["You are in a petite dining room. You can only go north", 0, None, None, None]
room_list.append(room)
# Hallway
room =["You are in a modern hallway. Choose between east, west, or south.", None, 3,0,4]
room_list.append(room)
# Kitchen
room =["You are in a brand new kitchen. You can go west to the hallway or east to the pantry.", 5, None, None, 2]
room_list.append(room)
# Bedroom
room =["You're in the biggest master bedroom. There's a hallway to the east and a bathroom to the north.", 6,2, None, None]
room_list.append(room)
# Pantry
room =["You are in a small pantry. You can only go west back to the kitchen.", None, None, None, 3]
room_list.append(room)
# Bathroom
room =["You are in a clean bathroom. You can only go south back to the bedroom.", None, None, 4, None]
room_list.append(room)
# Starting in the living room
current_room =0
# Main game loop
done = False
while not done:
# Print the room description
print("
"+ room_list[current_room][0])
# Get the player's choice of direction
direction = input("Where do you want to go?").lower()
# Move the player based on input and room connections
if direction =='n' and room_list[current_room][1] is not None:
current_room = room_list[current_room][1]
elif direction =='e' and room_list[current_room][2] is not None:
current_room = room_list[current_room][2]
elif direction =='s' and room_list[current_room][3] is not None:
current_room = room_list[current_room][3]
elif direction =='w' and room_list[current_room][4] is not None:
current_room = room_list[current_room][4]
else:
print("You can't go that way!")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+5.14. Let f (x) be n2x or 2n -n2x or 0 according as 0 5x

Answered: 1 week ago

Question

assess the infl uence of national culture on the workplace

Answered: 1 week ago