I want a room to be removed from my dictionary from the start of the game while snowboots = False. When snowboots = True, I want the room to be reachable, and I want picking up the snowboots to make them True.
if that makes sense.
roomDirections = {
"hallEnt":{"e":"hallMid"},
"hallMid":{"s":"snowRoom", "e":"giantNature", "w":"hallEnt"},
"snowRoom":{"n":"hallMid"},
"giantNature":{"s":"strangeWall", "e":"riverBank", "w":"hallMid"},
"strangeWall":{"s":"hallOuter", "e":"riverBank", "n":"giantNature"},
"riverBank":{"e":"lilyOne", "w":"giantNature"},
"lilyOne":{"e":"lilyTwo", "w":"riverBank", "n":"riverBank", "s":"riverBank"},
"lilyTwo":{"e":"riverBank", "w":"lilyThree", "n":"riverBank", "s":"riverBank"},
"lilyThree":{"e":"riverBank", "w":"lilyFour", "n":"riverBank", "s":"riverBank"},
"lilyFour":{"e":"riverBank", "w":"treasureRoom", "n":"riverBank", "s":"riverBank"},
"treasureRoom":{"w":"hallEnt"},
}
roomItems = {
"hallEnt":["snowboots"],
"snowRoom":["lamp"],
"treasureRoom":["treasure"],
}
snowboots = lamp = treasure = False
these are my dictionaries and my alleged variables.
if "snowboots" == False:
del roomDirections["hallMid"]
else:
print ("you cannot go that way")
this was meant to remove hallMid from roomDirections so movement from it is impossible, until...
elif playerInput in roomItems[currentRoom]:
print("picked up", playerInput)
invItems.append(playerInput)
playerInput == True
for i in range(0, len(roomItems[currentRoom])):
if playerInput == roomItems[currentRoom][i]:
del roomItems[currentRoom][i]
break
the snowboots = True, which is what this chunk was suppose to do but it doesn't seem to be working, am I close or am I completely off track?
EDIT -- My main game loop --
while True:
playerInput = input("What do you want to do? ")
playerInput = playerInput.lower()
if playerInput == "quit":
break
elif playerInput == "look":
print(roomDescriptions[currentRoom])
elif playerInput in dirs:
playerInput = playerInput[0]
if playerInput in roomDirections[currentRoom]:
currentRoom = roomDirections[currentRoom][playerInput]
print(roomEntrance [currentRoom])
else:
print("You can't go that way")
elif playerInput == "lookdown":
if currentRoom in roomItems.keys():
print ("You see", roomItems[currentRoom])
else:
print ("You see nothing on the ground")
elif playerInput == "inventory" or playerInput == "inv":
print (invItems)
elif playerInput in roomItems[currentRoom]:
print("picked up", playerInput)
invItems.append(playerInput)
for i in range(0, len(roomItems[currentRoom])):
if playerInput == roomItems[currentRoom][i]:
del roomItems[currentRoom][i]
break
elif playerInput in invItems:
print("dropped", playerInput)
roomItems[currentRoom].append (playerInput)
for i in range (0, len(invItems)):
if playerInput == invItems[i]:
del invItems[i]
break
else:
print ("I don't understand")
As I understand it, you want to add some conditions to decide whether going through a particular exit is allowed. You currently have dictionaries mapping the directions from each room, variables intended to hold whether the player has each item, and lists of items in each room and the player inventory. Note that the item variables are redundant; you could simply check the inventory.
Your proposed method is to add and remove exits from the rooms when the required items are acquired or lost. This can be done, but the complexity of finding which exits to remove is all you need to disregard them in the first place; restoring them if they were removed is harder than filtering them out as needed. Here's one approach:
You can then use these to ignore a direction if the condition was not satisfied:
You could also make it so players can't remove the required item in the room:
It may make sense to have a more object oriented approach, where a room actually contains its list of items, links to the other rooms, and requirements. You could also do things like add synonyms to items.