Added the map to my game in case that might be helpful in some way? I've tried my best to figure this out on my own using my textbook and the very helpful, useful answers already supplied here. However, it feels as though every attempt to fix my code only makes it worse. I'm certain my loop is causing the issue, but I can't figure out where I went wrong.
It prints everything correctly and asks for the input but, when I type in the input, it only calls the first loop. I thought it might be an indention problem, but PyCharm throws a fit when I indent the second loop. Thank you in advance.
**Updated "quit" or "QUIT" Thanks again, jarmod! ***Updated with latest code, thanks trincot!
Screenshot of output to show current issue:Input is needed twice before updating room and inventory? I see the formatting issue with the inventory. I think I can fix that... Maybe.
Here is my code:
spaces = {
"the outdoors": {"UP": "Barn", "RIGHT": "Magistrate's Home", "DOWN": "Candy Store"},
"Flowerhaus": {"RIGHT", "Barn"},
"Barn": {"LEFT": "Flowerhaus", "RIGHT": "Random Cabin", "DOWN": "the outdoors"},
"Magistrate's Home": {"UP": "Random Cabin", "DOWN": "Workshop", "LEFT": "the outdoors"},
"Workshop": {"UP": "Magistrate's Home", "LEFT": "Candy Store"},
"Candy Store": {"UP": "the outside", "LEFT": "Tavern", "RIGHT": "Workshop", "DOWN": "Papermill"},
"Tavern": {"RIGHT": "Candy Store", "DOWN": "Empty House"},
"Empty House": {"UP": "Tavern", "RIGHT": "Papermill"},
"Papermill": {"UP": "Candy Store", "LEFT": "Empty House"},
"Random Cabin": {"DOWN": "Magistrate's Home", "LEFT": "Barn"},
} # Dictionary for rooms and directions
items = {"Flowerhaus": None, "Tavern": None, "Barn": "Car Key", "Random Cabin": "Neighbor's Key",
"Magistrate's Home": "Deadbolt Key", "Workshop": "Office Key", "Empty House": "House Key",
"Papermill": "Mailbox Key", "Candy Store": "Ex's Key"} # Rooms as keys and key items as values.
current_space = "the outdoors" # Player starts outside
current_inventory = "a whole lot of nothing"
avail_directions = "UP", "DOWN", "RIGHT"
print("It's been a long, long, frustrating day.") # Print the story
print("You've entered the front door to your home, ready to take your shoes off and relax...")
print("As you walk through the door, you realize this is not your house, your city, or even your realm of existence.")
print("Warily, you step forward to further take in your surroundings.")
print("The floor is dirt, the buildings around you look strange, and the people don't seem to react to your presence.")
print("")
print("After a short time, you realize your keys are no longer in your hand.")
print("As you turn back around, you notice the door is still there, but now it has seven locks, each appearing")
print("to match the locks that go to all seven of your keys.")
print("Turning the knob proves the portal home is locked.")
print("Find all seven keys to unlock the door. Fail to find all seven keys and the door will disappear,")
print("leaving you trapped forever.")
print("")
print("So, with all of that in mind, where would you like to look first?") # End of printed story
direction = input("Type UP, DOWN, LEFT, or RIGHT").upper()
while direction != exit:
while direction in avail_directions:
print("You are currently in", current_space, "with", current_inventory, "on your keyring.") # Current status
direction = input("Type UP, DOWN, LEFT, or RIGHT").upper()
if direction in avail_directions:
current_space = spaces[current_space][direction]
avail_directions = tuple(spaces[current_space])
if current_space in items.keys():
if current_inventory == "a whole lot of nothing":
current_inventory = items[current_space]
print("You walk through the door and enter", current_space, end=".")
print("You found the", current_inventory, ".".strip())
else:
current_inventory += items[current_space]
print("You walk through the door and enter", current_space, end=".")
print("You found the", current_inventory, end=".")
elif direction == "QUIT":
print("Oh... So, you're going to take a break then? Yeah, maybe a nap is a good idea. Try again later.")
break
else:
print("Nothing over here. Don't you want to get back home? Try a different direction.")
continue
else:
print("Nothing over here. Don't you want to get back home? Try a different direction.")
direction = input("Type UP, DOWN, LEFT, or RIGHT").upper()
source https://stackoverflow.com/questions/72586007/moving-between-rooms-in-python
Comments
Post a Comment