For every correct guess the player makes I want a piece of an image to show. The image is a human.
so first correct guess = face, second correct guess = face and left hand, etc. My code is below if anyone can point me on the right path of what to check out / read or a link to look into that would be great. I was thinking tkinter, then PIL, then pygame but now I am so unsure.
I found some older posts about revealing pictures piece by piece but I do not think they are relevant to my needs.
Reveal a picture piece by piece
I am using a MacBook Pro Early-2015 running El Capitan and using PyCharm Community version and Python 3.5.2.
I found some code online to make a hangman game and I wanted to modify it to reveal part of an image as my "hangman" for every correct guess the user makes.
Is there any way to use tkinter and run the following?
Or maybe I am approaching it completely wrong?
I was thinking of adding
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))