Advertisement
Guest User

Untitled

a guest
Mar 10th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. #imports the necessary modules
  2. def wordImport(currentWord, openDoc, new, word):
  3. import random
  4. openDoc = open("Walrus.txt", "r")
  5. currentWord = []
  6. new = ""
  7. for i in range(0,random.randrange(0,70)):
  8. word = openDoc.readline()
  9. for i in range(0,int(len(word)-1)):
  10. currentWord.append(word[i])
  11. new = new + word[i]
  12. word = new
  13. import random
  14. import turtle
  15. turtle.speed(0)
  16. turtle.hideturtle()
  17. turtle.setx(0)
  18. turtle.sety(0)
  19. turtle.pd()
  20. #sets the variables
  21. letterCheck = 0
  22. lives = 10
  23. #opens the wordbank
  24. openDoc = open("Walrus.txt", "r")
  25. #defines the word as an array
  26. wordlist = []
  27. #makes a variable that is a random word
  28. ranWord = random.randrange(1,70)
  29. #reads the doc at the random line
  30. for i in range(0,ranWord):
  31. word = openDoc.readline()
  32. #makes a variable for the word length
  33. wordLength = int(len(word)-1)
  34. #makes an array for the word
  35. for i in range(0,wordLength):
  36. wordlist.append(word[i])
  37. #an array of the current word
  38. currentWord = wordlist
  39. length = len(word)
  40. #makes the array of hidden letters
  41. asterixArray = []
  42. length = len(word) - 1
  43. while length > 0:
  44. length = length - 1
  45. asterixArray.append("*")
  46. #compresses the array and shows the hidden word
  47. print ("This is the word:", ' '.join(asterixArray))
  48. #if the user is playing this will be one
  49. playing = 1
  50. #initiates a list to see what letter the user has put in
  51. letterList = []
  52. while playing == 1:
  53. letterCheck = 0
  54. print("You have", lives, "lives left ")
  55. #user inputs their guess
  56. userInput = input("What letter do you choose? ")
  57. userInput = userInput.lower()
  58. if userInput == "show":
  59. print(word)
  60. if len(userInput) == 1:
  61. #runs a comparison of the users guess to an array of previous guesses
  62. for i in letterList:
  63. if userInput == i:
  64. #changes if the user has inputted that letter before
  65. letterCheck = 1
  66. #runs the rest of the program if the users input is valid
  67. if letterCheck != 1:
  68. letterList.append(userInput)
  69. ticker = -1
  70. correct = 0
  71. #checks if it is correct
  72. for i in currentWord:
  73. #so I know how many times the loop has completed
  74. ticker = ticker + 1
  75. if userInput == i:
  76. asterixArray[ticker] = userInput
  77. correct = 1
  78.  
  79. if correct > 0:
  80. print("Correct!")
  81.  
  82. if correct != 1:
  83. print ("Incorrect!")
  84. lives = lives - 1
  85. if lives == 9:
  86. turtle.rt(180)
  87. turtle.fd(100)
  88. elif lives == 8:
  89. turtle.bk(30)
  90. turtle.rt(90)
  91. turtle.fd(200)
  92. elif lives == 7:
  93. if done8 == 0:
  94. turtle.rt(90)
  95. turtle.fd(100)
  96. done8 = 1
  97. elif lives == 6:
  98. turtle.bk(25)
  99. turtle.rt(90)
  100. turtle.fd(25)
  101. elif lives == 5:
  102. turtle.rt(90)
  103. circle=1
  104. while circle<55:
  105. turtle.fd(3)
  106. turtle.lt(10)
  107. circle=circle+1
  108. elif lives == 4:
  109. turtle.rt(90)
  110. turtle.fd(70)
  111. elif lives == 3:
  112. turtle.rt(30)
  113. turtle.fd(40)
  114. turtle.bk(40)
  115. elif lives == 2:
  116. turtle.lt(60)
  117. turtle.fd(40)
  118. turtle.bk(40)
  119. elif lives == 1:
  120. turtle.rt(30)
  121. turtle.bk(50)
  122. turtle.rt(40)
  123. turtle.fd(35)
  124. turtle.bk(35)
  125. elif lives == 0:
  126. turtle.lt(80)
  127. turtle.fd(35)
  128. turtle.bk(35)
  129. turtle.rt(40)
  130. elif lives == 0:
  131. #checks to see if you win
  132. print("You lose! The word was:", word)
  133. playing = 0
  134. print ("This is the word:", ' '.join(asterixArray))
  135. #checks to see if you won
  136. numberOfAsterix = asterixArray.count("*")
  137. if numberOfAsterix == 0:
  138. print("Congratulations, you win!")
  139. playing = 0
  140. #Tells the user they have already inputted a letterList
  141. else:
  142. print("You have already input that letter. Try again")
  143. else:
  144. print("You can only enter one letter!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement