私はPythonのゲーム開発の本から取られた次のスクリプトを持っています。著者は、1つを除いてすべてを説明します。私は自分自身でそれを理解しようとしましたが、初心者としてはそれほど意味がありません。ここでは、コードは次のようになります。この特定のパラメータはどのように値を受け取るのですか?
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
ではありません。ここで何が起きてるの?私は何が欠けていますか?
申し訳ありません、これは初心者向けの完全な質問です。 chosenCave
がcheckCave()
caveNumber
に渡されるところ
これは完璧な意味合いです。ありがとう、私は実際には、今日かなり早い数時間前から立ち往生していました。 –