每正確猜測玩家讓我想要一張圖片顯示。該圖像是一個human。Python根據條件一張一張地顯示圖片
第一個正確的猜測=臉部,第二個正確的猜測=臉部和左手等我的代碼如果任何人都可以指向我檢查/很棒。我正在考慮tkinter,然後是PIL,然後pygame,但現在我很不確定。
我發現了一些關於逐張顯示圖片的舊帖子,但我不認爲它們與我的需求相關。
Reveal a picture piece by piece
我使用的是MacBook Pro的早期2015年運行埃爾卡皮坦和使用PyCharm社區版和Python 3.5.2。
我在網上發現了一些代碼來製作hang子手遊戲,並且我想修改它以揭示圖像的一部分,作爲我的「hang子手」,以供用戶進行每次正確的猜測。
有什麼辦法可以使用tkinter並運行以下內容?
或者我正在接近它完全錯誤?
我想加入
import Image
Image.show # But this would not call back only a piece of an image,
#unless I could use image.slicer to cut the image up before hand and
#save the image as multiple pieces and add it. But this seems inefficient
import random
words = ['GOOGLE', 'FACEBOOK', 'NETFLIX', 'AMAZON']
while True:
start = input("Press enter/return to start")
if start == "" \
"":
break
secret_word = random.choice(words)
bad_guesses = []
good_guesses = []
while len(bad_guesses) < 10 and len(good_guesses) != len(list(secret_word)):
# show guessed letter, spaces and strikes
for letter in secret_word:
if letter in good_guesses:
print(letter, end='')
#For every letter in good_guesses we should reveal part of the image
else:
print('_ ', end='')
print('')
print('Strikes: {}/10'.format(len(bad_guesses)))
print('')
#user guesses letter
guess = input("Guess a letter! : ").upper()
if len(guess) != 1:
print ("You have to guess one letter at a time!")
continue
elif guess in bad_guesses or guess in good_guesses:
print("You already guessed this letter, try another letter!")
continue
elif not guess.isalpha():
print("You can only guess letters nothing else!")
continue
if guess in secret_word:
good_guesses.append(guess)
# for every good guess we want to add a picture to appear
if len(good_guesses) == len(list(secret_word)):
print("You win! The word was {}".format(secret_word))
break
else:
bad_guesses.append(guess)
else:
print("Sorry! the word was {}".format(secret_word))