Advertisement
Guest User

Untitled

a guest
May 6th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. import random
  2.  
  3. words = ['egypt', 'automobile', 'world', 'python', 'miniority', 'treehouse', 'friend', 'program' , 'people']
  4.  
  5. def start():
  6. print "Hello! Welcome to a tiny hangman game that I made for exercise purposes."
  7. raw_input('Press enter to continue')
  8.  
  9. key = random.randint(0,(len(words)-1))
  10.  
  11. global word
  12. word = words[key]
  13.  
  14. global word_template
  15. word_template = '_' * len(word)
  16. word_template = list(word_template)
  17.  
  18. guesser()
  19.  
  20. def draw(int):
  21. if int == 0:
  22. print " _________ "
  23. print "| | "
  24. print "| "
  25. print "| "
  26. print "| "
  27. print "| "
  28. print "| "
  29. elif int == 1:
  30. print " _________ "
  31. print "| | "
  32. print "| 0 "
  33. print "| "
  34. print "| "
  35. print "| "
  36. print "| "
  37. elif int == 2:
  38. print " _________ "
  39. print "| | "
  40. print "| 0 "
  41. print "| | "
  42. print "| "
  43. print "| "
  44. print "| "
  45. elif int == 3:
  46. print " _________ "
  47. print "| | "
  48. print "| 0 "
  49. print "| /| "
  50. print "| "
  51. print "| "
  52. print "| "
  53. elif int == 4:
  54. print " _________ "
  55. print "| | "
  56. print "| 0 "
  57. print "| /|\ "
  58. print "| "
  59. print "| "
  60. print "| "
  61. elif int == 5:
  62. print " _________ "
  63. print "| | "
  64. print "| 0 "
  65. print "| /|\ "
  66. print "| / "
  67. print "| "
  68. print "| "
  69. elif int == 6:
  70. print " _________ "
  71. print "| | "
  72. print "| 0 "
  73. print "| /|\ "
  74. print "| / \ "
  75. print "| "
  76. print "| "
  77.  
  78. def guesser():
  79. global counter
  80. counter = 0
  81. checker = list(word)
  82. guesses = []
  83. while counter < 6:
  84. draw(counter)
  85. print word_template
  86. print 'nYour previous letters are:', guesses
  87. print 'You have ',(6 - counter), 'guesses left.'
  88. choice = raw_input('Choose a letter: ')
  89. if choice in guesses:
  90. print "nYou made that guess before!"
  91. elif choice in checker:
  92. if checker.count(choice) == 1:
  93. pointer = checker.index(choice)
  94. word_template[pointer] = checker[pointer]
  95. checker[pointer] = 1
  96. guesses.append(choice)
  97. print "nThat's a hit!"
  98. if list(word) == word_template:
  99. win()
  100. else:
  101. continue
  102. elif checker.count(choice) > 1:
  103. for i in range(0, checker.count(choice)):
  104. pointer = checker.index(choice)
  105. word_template[pointer] = checker[pointer]
  106. checker[pointer] = 1
  107. guesses.append(choice)
  108. print "nWOW! That was a multiple hit!"
  109. if list(word) == word_template:
  110. win()
  111. else:
  112. continue
  113. elif choice not in checker:
  114. guesses.append(choice)
  115. counter += 1
  116. print 'nMiss!'
  117. if counter == 6:
  118. draw(counter)
  119. print 'Sorry, you lose :('
  120. print 'The word was:', word
  121. retry()
  122.  
  123. def win():
  124. print "nYou won!"
  125. print "You found the word:", word
  126. retry()
  127.  
  128. def retry():
  129. print "Do you want to play again?"
  130. choice = raw_input('Type retry for restart, Ctrl + C for exit:')
  131. if choice == 'retry':
  132. start()
  133. else:
  134. print "Sorry, I can't understand."
  135. retry()
  136.  
  137. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement