我有以下腳本是從Python遊戲開發書中提取的。作者解釋了一切,除了一件事。我試圖自己弄清楚,但作爲一個初學者,這沒什麼意義。下面是代碼:這個特定參數如何獲得一個值?
import random
import time
def displayIntro():
print('You are on a planet full of dragons. In front of you,')
print('you see two caves. In one cave, the dragon os friendly')
print('and will share his treasure with you. The other dragon')
print('is greedy and hungry, and will eat you on sight.')
print()
def chooseCave():
cave=''
while cave != '1' and cave != '2':
print('Which cave will you go into? (1 or 2)')
cave=input()
return cave
def checkCave(chosenCave):
print('You approach the cave...')
time.sleep(2)
print('It is dark and spooky...')
time.sleep(2)
print('A large dragon jumps out in front of you! He opens his jaws and...')
print()
time.sleep(3)
friendlyCave=random.randint(1,2)
if chosenCave==str(friendlyCave):
print('Gives you his treasure!')
else:
print('Gobbles you down in one bite.')
playAgain='yes'
while playAgain=='yes' or playAgain=='y':
displayIntro()
caveNumber=chooseCave()
checkCave(caveNumber)
print('Do you want to play again? (yes or no)')
playAgain=input()
現在我的問題是:如何在參數chosenCave
獲得價值?對我來說,它似乎沒有在任何地方定義。我們定義了什麼是cave
,什麼friendlyCave
是,但不是chosenCave
。這裏發生了什麼?我錯過了什麼?
對不起,如果這是一個完整的初學者問題。
哦,這很有道理。謝謝,今天早些時候我實際上已經停留了幾個小時。 – 2012-01-10 03:37:54