i am almost done with the hangman game but i just need to migrate it to graphics i know i need to use entrybox but i still dont know.
rom graphics import*
from random import *
MAX_BAD_GUESSES = 7
def readfile():
infile = open("wordlist.txt","r")
contents = infile.read()
lines = contents.split("\n")
return lines
def random(lines):
secret_word = randint(0,len(lines)-1)
return lines[secret_word].lower()
def play(secret_word):
guess = 0
solution = []
for i in range(len(secret_word)):
solution.append("_")
num_incorrect = 0
while num_incorrect < 7 and "_" in solution:
print(" ".join(solution))
guess = input("Enter a letter")
if secret_word.find(guess)==-1:
num_incorrect = num_incorrect +1
else:
i = secret_word.find(guess)
solution[i] = guess
if not '_' in solution:
print("Congratulations!")
print(secret_word)
else:
print("You Lost")
print(secret_word)
def drawBodyPart(drawObjects, win, incorrectGuesses):
baseIndex = 4 #items alread drawn
drawObjects[baseIndex + incorrectGuesses].draw(win)
def playGraphics(secret_word):
# create the window, the victim to be hanged, and the gallows.
win = GraphWin("Hangman", 600,650)
start_x = 200
obj_list = []
obj_list.append(Rectangle(Point(100,350),Point(370,400)))
obj_list.append(Rectangle(Point(100,400),Point(300,600)))
obj_list.append(Line(Point(500,150),Point(500,100)))
obj_list.append(Line(Point(500,100),Point(400,100)))
obj_list.append(Line(Point(400,100),Point(400,500)))
for obj in obj_list:
obj.draw(win)
obj_list.append(Circle(Point(500,200),50))
obj_list.append(Line(Point(500,250),Point(500,380)))
obj_list.append(Line(Point(500,380),Point(450,450)))
obj_list.append(Line(Point(500,380),Point(550,450)))
obj_list.append(Line(Point(500,300),Point(450,380)))
obj_list.append(Line(Point(500,300),Point(550,380)))
obj_list.append(Text(Point(250,150), "You SUCK at Hangman!!"))
solution = []
for i in range(len(secret_word)):
solution.append("_")
badGuessCount = 0
while badGuessCount < MAX_BAD_GUESSES and "_" in solution:
print(" ".join(solution))
guess = input("Enter a letter")
if secret_word.find(guess)==-1:
badGuessCount += 1
drawBodyPart(obj_list, win, badGuessCount)
else:
i = secret_word.find(guess)
while (i > -1):
solution[i] = guess
i = secret_word.find(guess, i + 1)
if not '_' in solution:
playerMessage = obj_list[-1]
print(obj_list[0] == obj_list[-len(obj_list)])
# obj_list[len(obj_list) - 1] == obj_list[-1]
# obj_list[0] == obj_list[-len(obj_list)]
playerMessage.setText("Congratulations! You don't SUCK at Hangman!")
playerMessage.draw(win)
print("Congratulations!")
print(secret_word)
else:
print("You Lost")
print(secret_word)
win.getMouse()
win.close()
def main():
words = readfile()
word = random(words)
#play(word)
playGraphics(word)
thats all i have so far !