snowboots = False 인 동안 게임을 시작할 때 사전을 삭제하고 싶습니다. snowboots = True 일 때, 나는 그 방에 도달 할 수 있기를 원하며, 나는 snowboots를 집어 들고 그것을 참되게 만들고 싶다.항목 조건에 따라 사전 항목을 제거하는 방법
그것이 의미가있는 경우.
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
snowboots이 덩어리가해야 할 생각했지만 그것은 아무튼 무엇 인 = 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")
'''elif'' 스위트가'''snowboots''에''True''를 할당하기를 원한다는 말입니까? 그렇다면 단지 할당 문을 추가하십시오. '''playerInput == True'''는 효과가없는 문장입니까? – wwii
나는 할당 문이 미안하다는 것을 모른다. 나는 파이썬에 대해 아주 새로운 것이다. 편집 : 'elif'스위트는 게임의 세 항목 모두를 선택하기도하지만, 플레이어가 오른쪽 방에있을 때만 가능합니다. – kebab
'''a = 3'''은 할당 문입니다. 'a'. – wwii