Hangman Game with Graphics
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
from graphics import Graphics
from time import sleep
import random
class Hangman(object):
def __init__(self, word):
self.word = word
self.used_letters = ""
self.current_letter = ""
@property
def grid(self):
grid = ""
for i in self.word:
if i in self.used_letters:
grid += i
else:
grid += "_ "
return grid
def show_grid(self):
print("Used Letters: " + self.used_letters)
print("n" + self.grid)
def ask_letter(self):
while True:
letter = input("Guess a letter: ").lower()
self.current_letter = letter
if len(self.current_letter) > 1:
print("nYou have entered to many letters!")
else:
if self.current_letter in self.used_letters:
print("This letter has already been used!")
continue
else:
self.used_letters += self.current_letter + " "
return "Letter Added"
def check(self):
if self.current_letter in self.word:
if "_" in self.grid:
return "Continue Game"
else:
return "Winner"
else:
return "Not a letter"
def winner(self):
print("n")
print("You have won!!")
print("nWould you like to play again?")
reply = input("Y/N?").lower()
if reply == "y":
print("n")
main()
else:
print("Thank you for playing!")
exit()
def lost(self):
print("n")
print("You have lost!")
print(Graphics[0])
print("The word was: " + self.word)
sleep(2)
print("nWould you like to play again?")
reply = input("Y/N?").lower()
if reply == "y":
print("n")
main()
else:
print("Thank you for playing!")
exit()
def main():
words = ["hello", "goodbye"]
attempts = 8
hangman = Hangman(random.choice(words))
while attempts > 0:
hangman.show_grid()
hangman.ask_letter()
hangman.check()
if hangman.check() == "Winner":
hangman.winner()
if hangman.check() == "Not a letter":
attempts -= 1
print(Graphics[attempts])
print("0 attempts remain".format(attempts))
print("n")
hangman.lost()
if __name__ == "__main__":
main()
I am looking for any advice on how to improve my hangman game.
The graphics are in a separate document. It is just images of the hangman.
python game hangman
add a comment |Â
up vote
3
down vote
favorite
from graphics import Graphics
from time import sleep
import random
class Hangman(object):
def __init__(self, word):
self.word = word
self.used_letters = ""
self.current_letter = ""
@property
def grid(self):
grid = ""
for i in self.word:
if i in self.used_letters:
grid += i
else:
grid += "_ "
return grid
def show_grid(self):
print("Used Letters: " + self.used_letters)
print("n" + self.grid)
def ask_letter(self):
while True:
letter = input("Guess a letter: ").lower()
self.current_letter = letter
if len(self.current_letter) > 1:
print("nYou have entered to many letters!")
else:
if self.current_letter in self.used_letters:
print("This letter has already been used!")
continue
else:
self.used_letters += self.current_letter + " "
return "Letter Added"
def check(self):
if self.current_letter in self.word:
if "_" in self.grid:
return "Continue Game"
else:
return "Winner"
else:
return "Not a letter"
def winner(self):
print("n")
print("You have won!!")
print("nWould you like to play again?")
reply = input("Y/N?").lower()
if reply == "y":
print("n")
main()
else:
print("Thank you for playing!")
exit()
def lost(self):
print("n")
print("You have lost!")
print(Graphics[0])
print("The word was: " + self.word)
sleep(2)
print("nWould you like to play again?")
reply = input("Y/N?").lower()
if reply == "y":
print("n")
main()
else:
print("Thank you for playing!")
exit()
def main():
words = ["hello", "goodbye"]
attempts = 8
hangman = Hangman(random.choice(words))
while attempts > 0:
hangman.show_grid()
hangman.ask_letter()
hangman.check()
if hangman.check() == "Winner":
hangman.winner()
if hangman.check() == "Not a letter":
attempts -= 1
print(Graphics[attempts])
print("0 attempts remain".format(attempts))
print("n")
hangman.lost()
if __name__ == "__main__":
main()
I am looking for any advice on how to improve my hangman game.
The graphics are in a separate document. It is just images of the hangman.
python game hangman
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
from graphics import Graphics
from time import sleep
import random
class Hangman(object):
def __init__(self, word):
self.word = word
self.used_letters = ""
self.current_letter = ""
@property
def grid(self):
grid = ""
for i in self.word:
if i in self.used_letters:
grid += i
else:
grid += "_ "
return grid
def show_grid(self):
print("Used Letters: " + self.used_letters)
print("n" + self.grid)
def ask_letter(self):
while True:
letter = input("Guess a letter: ").lower()
self.current_letter = letter
if len(self.current_letter) > 1:
print("nYou have entered to many letters!")
else:
if self.current_letter in self.used_letters:
print("This letter has already been used!")
continue
else:
self.used_letters += self.current_letter + " "
return "Letter Added"
def check(self):
if self.current_letter in self.word:
if "_" in self.grid:
return "Continue Game"
else:
return "Winner"
else:
return "Not a letter"
def winner(self):
print("n")
print("You have won!!")
print("nWould you like to play again?")
reply = input("Y/N?").lower()
if reply == "y":
print("n")
main()
else:
print("Thank you for playing!")
exit()
def lost(self):
print("n")
print("You have lost!")
print(Graphics[0])
print("The word was: " + self.word)
sleep(2)
print("nWould you like to play again?")
reply = input("Y/N?").lower()
if reply == "y":
print("n")
main()
else:
print("Thank you for playing!")
exit()
def main():
words = ["hello", "goodbye"]
attempts = 8
hangman = Hangman(random.choice(words))
while attempts > 0:
hangman.show_grid()
hangman.ask_letter()
hangman.check()
if hangman.check() == "Winner":
hangman.winner()
if hangman.check() == "Not a letter":
attempts -= 1
print(Graphics[attempts])
print("0 attempts remain".format(attempts))
print("n")
hangman.lost()
if __name__ == "__main__":
main()
I am looking for any advice on how to improve my hangman game.
The graphics are in a separate document. It is just images of the hangman.
python game hangman
from graphics import Graphics
from time import sleep
import random
class Hangman(object):
def __init__(self, word):
self.word = word
self.used_letters = ""
self.current_letter = ""
@property
def grid(self):
grid = ""
for i in self.word:
if i in self.used_letters:
grid += i
else:
grid += "_ "
return grid
def show_grid(self):
print("Used Letters: " + self.used_letters)
print("n" + self.grid)
def ask_letter(self):
while True:
letter = input("Guess a letter: ").lower()
self.current_letter = letter
if len(self.current_letter) > 1:
print("nYou have entered to many letters!")
else:
if self.current_letter in self.used_letters:
print("This letter has already been used!")
continue
else:
self.used_letters += self.current_letter + " "
return "Letter Added"
def check(self):
if self.current_letter in self.word:
if "_" in self.grid:
return "Continue Game"
else:
return "Winner"
else:
return "Not a letter"
def winner(self):
print("n")
print("You have won!!")
print("nWould you like to play again?")
reply = input("Y/N?").lower()
if reply == "y":
print("n")
main()
else:
print("Thank you for playing!")
exit()
def lost(self):
print("n")
print("You have lost!")
print(Graphics[0])
print("The word was: " + self.word)
sleep(2)
print("nWould you like to play again?")
reply = input("Y/N?").lower()
if reply == "y":
print("n")
main()
else:
print("Thank you for playing!")
exit()
def main():
words = ["hello", "goodbye"]
attempts = 8
hangman = Hangman(random.choice(words))
while attempts > 0:
hangman.show_grid()
hangman.ask_letter()
hangman.check()
if hangman.check() == "Winner":
hangman.winner()
if hangman.check() == "Not a letter":
attempts -= 1
print(Graphics[attempts])
print("0 attempts remain".format(attempts))
print("n")
hangman.lost()
if __name__ == "__main__":
main()
I am looking for any advice on how to improve my hangman game.
The graphics are in a separate document. It is just images of the hangman.
python game hangman
edited Apr 4 at 12:58
asked Apr 4 at 11:47
dranoelmas
162
162
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Â
draft saved
draft discarded
Â
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f191241%2fhangman-game-with-graphics%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password