Hangman Game with Graphics

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|improve this question



























    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.







    share|improve this question























      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.







      share|improve this question













      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.









      share|improve this question












      share|improve this question




      share|improve this question








      edited Apr 4 at 12:58
























      asked Apr 4 at 11:47









      dranoelmas

      162




      162

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          Chat program with C++ and SFML

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          Will my employers contract hold up in court?