0
import random

HANGMANPICS = ['''

+------+
|      |
|      |
       |
       |
       |
       |
       |
       |
       |
       |
==============''', '''

+      +
|      |
|      |
O      |
       |
       |
       |
       |
       |
       |
       |
==============''', '''
+------+
|      |
|      |
|      |
O      |
|      |
|      |
|      |
       |
       |
==============''']

words = 'ant baboon badger bat bear beaver beetle bird camel cat clam cobra cougar coyote crab crane crow deer dog donkey duck eagle ferret fish fox frog goat goose hawk iguana jackal koala leech lemur lion lizard llama mite monkey moose moth mouse mule newt otter owl oyster panda parrot pigeon python quail rabbit ram rat raven rhino salmon seal shark sheep skunk sloth slug snail snake spider squid stork swan tick tiger toad trout turkey turtle wasp weasel whale wolf wombat worm zebra'.split()

# This function returns a random string from the list of strings.
def getRandomWord(wordList): 
    wordIndex = random.randint(0, len(wordList) - 1)
return wordList[wordIndex]

def displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord):
    print HANGMANPICS[len(missedLetters)]
print

print 'Missed Letters:',
for letter in missedLetters:
    print letter,
print

blanks = '_' * len(secretWord)

for i in range(len(secretWord)):
  if secretWord[i] in correctLetters:
    blanks = blanks[:i] + secretWord[i] + blanks[i+1:]

for letter in blanks:
    print letter,
print

def getGuess(alreadyGuessed):
    while True:
        print 'Guess a letter.'
        guess = raw_input()
        guess = guess.lower()
        if len(guess) != 1:
            print 'Please enter a single letter.'
        elif guess in alreadyGuessed:
            print 'You have already guessed that letter. Choose again.'
        elif guess not in 'abcdefghijklmnopqrstuvwxyz':
            print 'Please enter a LETTER.'
        else:
            return guess

def playAgain():
    print 'Do you want to play again? (yes or no)'
    return raw_input().lower().startswith('y')


print 'HANGMAN'
missedLetters = ''
correctLetters = ''
secretWord = getRandomWord(words)
gameIsDone = False

while True:
    displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord)

    guess = getGuess(missedLetters + correctLetters)

if guess in secretWord:
    correctLetters = correctLetters + guess

    foundAllLetters = True
    for i in range(len(secretWord)):
        if secretWord[i] not in correctLetters:
            foundAllLetters = False
            break
    if foundAllLetters:
        print 'Yes! The secret word is "' + secretWord + '"! You have won!'
        gameIsDone = True
else:
  missedLetters = missedLetters + guess

  if len(missedLetters) == len(HANGMANPICS) - 1:
    displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord)
    print 'You have run out of guesses!\nAfter ' + str(len(missedLetters)) + ' missed guesses and ' + str(len(correctLetters)) + ' correct guesses, the word was "' + secretWord + '"'
    gameIsDone = True

if gameIsDone:
    if playAgain():
        missedLetters = ''
        correctLetters = ''
        gameIsDone = False
        secretWord = getRandomWord(words)
    else:
        break

2 番目の関数 displayBoard では、4 つのパラメーターが渡されます。HANGMANPICS、missedLetters、secretWord は理解できますが、correctLetters の引数がどこで定義/置換されているかがわかりません。

素人の言葉で(私は初心者なので)、正しい文字が何をすべきかはどこに書かれていますか?私はこのゲームを 1 週間勉強してきましたが、これを除いて、今のところすべて問題ないようです。

助けてください。

4

2 に答える 2