forked from tjguk/kelston_mu_code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hangman_screen.py
140 lines (101 loc) · 2.45 KB
/
hangman_screen.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
import turtle as t
NUMBER_TO_FAIL = 10
def draw_word(word_so_far):
t.penup()
t.setpos(50,225)
t.write(word_so_far, font=("Arial", 28, "normal"))
def draw_hangman(failed_letters):
Letters = len(failed_letters)
t.penup()
t.setpos(50,25)
t.speed(4)
t.pensize(6)
t.penup()
t.left(180)
t.forward(150)
t.left(90)
t.forward(100)
t.pencolor("saddle brown")
if Letters >= 1:
t.pendown()
t.right(90)
t.forward(100)
if Letters >= 2:
t.right(90)
t.forward(200)
if Letters >= 3:
t.right(90)
t.forward(200)
if Letters >= 4:
t.left(180)
t.forward(150)
t.left(45)
t.forward(70)
t.right(180)
t.forward(70)
t.right(45)
t.forward(50)
if Letters >= 5:
t.pencolor("sandy brown")
t.right(90)
t.forward(50)
if Letters >= 6:
t.pencolor("firebrick3")
t.circle(10)
if Letters >= 7:
t.forward(55)
if Letters >= 8:
t.right(45)
t.forward(25)
t.left(180)
t.forward(25)
if Letters >= 9:
t.right(90)
t.forward(25)
t.left(180)
t.forward(25)
if Letters >= 10:
t.right(45)
t.forward(25)
t.right(90)
t.forward(25)
t.left(180)
t.forward(50)
def draw(word_so_far, failed_letters):
"""Draw the word so far and the hangman
(Might also draw the list of failed letters)
Useful:
reset -- starts again with a clear screen
write -- writes text to the screen
"""
t.reset()
draw_word(" ".join(word_so_far))
draw_hangman(failed_letters)
#print("Word So Far : ",word_so_far,"\nFailed Letters : ",failed_letters)
def get_a_letter():
"""Prompt the user to enter a letter
"""
#
# HINT: turtle.textinput might help
#
text = t.textinput("Hangman", "Set me one").upper()
return text
def get_difficulty():
"""Return a number showing how difficult
"""
return int(t.textinput("Hangman", "How difficult?"))
def win_or_lose(wl):
"""wl means win or lose
"""
if wl:
t.reset()
t.penup()
t.setpos(50,225)
t.write("You Won !!!", font=("Arial", 28, "normal"))
else:
t.reset()
t.penup()
t.setpos(50,225)
t.write("You Lost !!!", font=("Arial", 28, "normal"))
if __name__=="__main__":
draw(list("Memes"),list("irrelevent") )