0
ハングマンゲーム用のコードにグラフィックを追加しようとしました。グラフィックスは出現しなかったし、手紙を推測すると自動的にゲームが終了したと言われる。私は何が間違っているのかよくわからないので、私はPythonとコーディングにはとても新しいです。ゲームが存在するPython Hangman Graphics
import random
Graphics=['''
------------
| |''','''
------------
| |
| O''','''
------------
| |
| O
| /|''','''
------------
| |
| O
| /|
| | ''','''
------------
| |
| O
| /|
| |
| /|
|
| ''']
start = str(input("Welcome to Hangman!"))
failures = 0
allowed = 6
guesses_left = 6
guessed = str()
wordlist = ['kittens' , 'keen', 'right', 'square', 'baseball','soccer', 'square','house', 'safe', 'pizza', 'pasta', 'Loyola', 'cat', 'dog', 'rambler', 'Chicago', 'Pittsburgh']
def correct(guess):
if guess in word:
if guess not in guessed:
print("Correct")
return(True)
else:
if guess not in word and len(guess) == 1 and guess in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ':
if guess not in guessed:
print("Incorrect!")
return(False)
print("Guess this word!")
print("You can input any letter from A to Z and the space key.")
wordnumber = random.randint(0, len(wordlist))
word = (wordlist[wordnumber])
guessed_letters = len(word) * ['_']
print(' '.join(guessed_letters))
while failures < allowed:
guess = str(input("Guess a letter!"))
if len(guess) != 1 or guess not in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ':
print("That is not a letter, try again.")
if guess in guessed:
print("You have already guessed that letter, try again.")
iscorrect = correct(guess)
guessed = guessed, guess
if iscorrect == True:
for position, letter in enumerate(word):
if letter == guess:
guessed_letters[position] = letter
print(' '.join(guessed_letters))
if iscorrect == False:
print("Wrong!")
failures = failures+1
guesses_left -= 1 # Number of guesses left
print("You have", guesses_left , "guesses left.")
if (guessed_letters == word):
print('''
You have successfully guessed the word!
''')
else:
print('''
You have lost the game!
''')
break
グラフィックを印刷しているところはありません。私は、あなたが "間違って!"という印字(グラフィックス[失敗])行を必要としていると思います。 – SteveJ