我寫了一個python文本冒險遊戲,我想添加的最後一件東西是一個計數器,可以計算在遊戲結束時顯示的轉數。打開python文本冒險計數器
它只需要計算每一次玩家輸入的東西,但林不知道如何編寫這一點,它有點尷尬因爲我確定這將是一個非常簡單的解決方案
IM使用Python 3.4.1
while True:
playerInput = input("What do you want to do? ")
playerInput = playerInput.lower()
playerWords = playerInput.split(" ", 1)
verb = playerWords[0]
if len(playerWords) == 2:
noun = playerWords[1]
else:
noun = ""
if playerInput == "quit":
break
elif playerInput == "look":
print(roomDescriptions[currentRoom])
##--Controls movement--##
elif playerInput in dirs:
playerInput = playerInput[0]
if "treasure" in invItems and playerInput == "s" and currentRoom == "strangeWall":##--Checks for treasure in inventory before allowing game to be won--##
print("!!!!Congratulations you have escaped from the dark dungeon!!!!")
break
elif playerInput in roomDirections[currentRoom]:
currentRoom = roomDirections[currentRoom][playerInput]
print(roomEntrance [currentRoom])
else:
print("You can't go that way")
elif playerInput == "lookdown":##--checks for room items on the ground--##
printList ("You see;", roomItems[currentRoom])
elif playerInput == "inventory" or playerInput == "inv":##--Displays inventory items--##
printList ("You are carrying;", invItems)
elif verb == "get":##--Controls picking up items and adding them to inventory/removes from room--##
if noun in roomItems[currentRoom]:
print("picked up", noun)
invItems.append(noun)
roomItems[currentRoom].remove(noun)
else:
print("There is nothing to pick up")
elif verb == "drop":##--Controls dropping items and removing them from the inventory/adds to room items--##
if noun in invItems:
print("You drop the", noun)
roomItems[currentRoom].append(noun)
invItems.remove(noun)
else:
print("You are not carrying", noun)
elif verb == "use":##--Controls using the lamp and snow boots--##
if noun in invItems:##--Checks inventory for lamp or snowboots before allowing certain directional movement--##
if noun == "lamp":
print("You light the lamp")
invItems.remove(noun)
roomDirections["hallMid"]["e"] = "giantNature"
elif noun == "snowboots":
print("You put on the snowboots")
invItems.remove(noun)
roomDirections["hallMid"]["s"] = "snowRoom"
else:
print("You cannot use that")
else:
print("You do not have", noun)
else:
print ("I don't understand")
哦對不起我不認爲你需要看到它,即時通訊仍然是一個新手 – kebab 2014-11-21 01:12:58
@kebab:沒問題。閱讀本網站上的幫助是一個好主意;有一些關於如何提出好問題的很好的信息。但與此同時,我更新了我的答案以處理更具體的問題(正如您所看到的,這樣做更簡單,這是提出更具體問題的好原因之一)。 – abarnert 2014-11-21 01:28:08
是啊我有它的唯一我的第三天使用該網站,只有我的第一學期的Python,所以我很明白,你仍然與我同時在我學習的同時,非常感謝 – kebab 2014-11-21 01:30:24