repl.it
@smwhalen94/

HangMan

Python (with Turtle)

No description

fork
loading
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
''' HangMan '''
#-------------------#
''' Source Code owned by Seth Whalen @smwhalen94 '''
#---------------------------------#
import turtle
turtle.speed(0)
#Global variable definitions
letters = ["A","B","C",'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
count = 0
guess = ""
word = ""
guesses = 0
number = 0
true2 = True
print_word = []
############# EO definitions ##############

####Letter guessing function####
def guess_word(guesses):
	guess = ""
	true = True
	while true:
		if guesses < 6:
			print_phrase(print_word)
			print ("\n")
			print ("You have %d limbs left" %(6-guesses))
			inputs = (input("Enter your guess:"))
			if inputs.isdigit() or inputs == "" or len(inputs) != 1 or " " in inputs or inputs.isalpha() == False :
				print ("\n" * 100)
				print ("Please enter a single letter")
			else:
				guess = inputs
				true = False	

	return guess	
################ EOFunc guess_word #################

#function that prints out the current standing of letters in the word/phrase
def print_phrase(words):
	i = 0
	while i < len(words):
		print (words[i]),
		i+=1
	return	
################# EOFunc print_phrase ##################

#function that rotates drawing cursor 180 degrees
def one_8():
	turtle.right(180)
	return
############# EOFunc one_8 ##################

#Function that draws a circle, useless since 'turtle.circle()' does the same thing
def circle():
	for i in range(360):
		turtle.forward(.6)
		turtle.right(1)
	return
############ EOFunc circle##############

### Drawing the Hanger
print ("Loading...")
turtle.forward(200)
turtle.backward(100)
turtle.left(90)
turtle.forward(500)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(50)
turtle.left(90)
print ("\n" * 100)
####### EO drawing hanger ##########
##Asking for player 1's word/phrase of choice###
while true2:
	word = input("Player 1, Enter a word or phrase for Player 2 to guess:")
	if word.isdigit()  or word == "" or (word.isalpha() or len(word) > 5) == False:
		print ("\n" * 100)
		print ("Please enter letters only")
	else:
		true2 = False	
############ EO word/phrase Input ################

### Creating empty list to hold Correct guessed letters and list version of "word/phrase" entered ###
print ("\n" * 100)
word = word.upper()
print_word = ["__"]*(len(word))
word3 = list(word)
if " " in word:
	word2 = list(word.upper())
	word2.remove(" ")
	word2 = str(word2)
else:
	word2 = list(word)
###### EO Lists ##############


##### Main Part of code, checks whether letter guesses are correct or duplicates. Prints results ##
##### and print a list of letters that have not been guessed ######################################
while count < 6:
	letter = guess_word(count)
	i = 0
	letter = letter.upper()

	while i < len(word3):
		if word3[i] == letter:
  		print_word[i] = letter

		elif word3[i] == " ":
			print_word[i] = " "	
		i+=1	
	
	number = 0

	if letter not in letters:
		print ("\n" * 100)
		print_phrase(print_word)
		print ("\n")
		print ("You already guessed the letter %s \n" %letter)
		print ("Letters you haven't guessed %s \n" %letters)

	elif letter in word2:
		print ("\n" * 100)
		#print_phrase(print_word)
		#print ("\n")
		print ("Good guess. the letter %s is in the word \n" %letter.upper())
		letter = letter.upper()
		letters.remove(letter)
		print ("Letters you haven't guessed %s \n" %letters)


	for i in letters:
		for j in word2:
			if j == i:
				number =+ 1	

	if number == 0:
		while i < len(word):
			if word3[i] == letter:
  			print_word[i] = letter
			i+=1
		print ("\n" * 100)
		print (" Congratulations! You won! the word/phrase is "),
		print_phrase(print_word)
		print ("\n")
		break

	if letter not in word2:

		if letter not in letters:
			print ("\n")	

		else:
			letter = letter.upper()
			letters.remove(letter)
			print ("\n" * 100)
			print ("The letter %s is not in the word" % letter)
			print ("Letters you haven't guessed %s \n" %letters)
			count += 1			

			'''Drawing the head'''
			if count == 1:
				print ("Drawing head...")
				turtle.right(180)
				turtle.circle(40)
				turtle.left(90)
				turtle.penup()
				turtle.forward(73)
				turtle.pendown()
				print ("\n" * 10)

			'''Drawing the body'''
			if count == 2:
				turtle.forward(100)

			'''Drawing right leg'''
			if count == 3:
				turtle.left(45)
				turtle.forward(50)
				turtle.backward(50)

			'''Drawing left leg'''
			if count == 4:
				turtle.right(90)
				turtle.forward(50)
				turtle.backward(50)
				turtle.right(135)
				turtle.forward(65)
				one_8()


			'''Drawing the right arm'''
			if count == 5:
				turtle.left(45)
				turtle.forward(35)
				turtle.backward(35)
				turtle.right(90)


'''Drawing the left arm'''
if count == 6 and number != 0:
	turtle.forward(35)
	turtle.backward(35)
	print ("\n" * 100)
	print ( " You lost :("),
	print ("The word/phrase was"),
	print (word)


	################## END OF PROGRAM ###########################
result
console
?