我希望从游戏开始时从我的字典中删除一个房间,而雪地靴 = False。当雪地靴 = True 时,我希望房间可以到达,并且我想拿起雪地靴使它们为 True。
如果这是有道理的。
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
这些是我的字典和我所谓的变量。
if "snowboots" == False:
del roomDirections["hallMid"]
else:
print ("you cannot go that way")
这是为了从 roomDirections 中删除 hallMid ,因此不可能从中移动,直到...
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
雪地靴 = True,这是这个块应该做的,但它似乎没有工作,我是关闭还是完全偏离轨道?
编辑——我的主要游戏循环——
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")