-
Notifications
You must be signed in to change notification settings - Fork 240
/
Hangman.py
146 lines (144 loc) · 4.99 KB
/
Hangman.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
#Build the Hangman Game using Python.
from random import *
import turtle
def film(f):
word=list(f)
check=[]
while len(check)<(len(word)/2):
wordindex=randint(0,len(word)-1)
if wordindex in check:
pass
else:
word[wordindex]='_'
check.append(wordindex)
s=''
return str(s.join(word))
guess=['bootstrap','springboot','javascript','github','kanban','react','flutter','nodejs']
play=True
while play:
guessindex=randint(0,len(guess)-1)
show=guess[guessindex]
turtle.bgcolor('teal')
turtle.color('white')
style = ('Courier', 30, 'italic')
turtle.penup()
turtle.goto(0,350)
turtle.pendown()
turtle.write('Welcome to Hangman Game!', font=style, align='center')
turtle.hideturtle()
turtle.penup()
turtle.goto(0,310)
turtle.pendown()
turtle.color('black')
techstyle = ('Courier', 20, 'italic')
turtle.write('Guess the tech : '+str(film(show)), font=techstyle, align='center')
print('\nGuess the tech : ',film(show))
lives=10
turtle.penup()
turtle.goto(100,-100)
turtle.pendown()
while lives:
print(str(lives) + " ❤ Remaining")
answer=input('\nAnswer : ')
if answer==show:
style = ('Courier', 30, 'italic')
turtle.penup()
turtle.goto(0,-260)
turtle.pendown()
turtle.color('black')
turtle.write(str(show), font=style, align='center')
turtle.penup()
turtle.goto(0,-310)
turtle.color('yellow')
turtle.write('!! Hurray You won the game !!', font=style, align='center')
turtle.hideturtle()
print('\nHurray You won the game !!!!')
break
else:
turtle.color('black')
turtle.shape("turtle")
lives -=1
print('\nOops Wrong answer')
print('Try again')
if lives==9:
turtle.color('brown')
turtle.pensize(70)
turtle.backward(300)
turtle.forward(40)
if lives==8:
turtle.pensize(30)
turtle.color('black')
turtle.left(90)
turtle.forward(350)
if lives==7:
turtle.pensize(30)
turtle.color('black')
turtle.right(90)
turtle.forward(120)
if lives==6:
turtle.pensize(10)
turtle.color('black')
turtle.right(90)
turtle.forward(40)
turtle.right(90)
turtle.forward(0)
if lives==5:
turtle.pensize(15)
turtle.color('white')
turtle.fillcolor('white')
turtle.circle(20)
turtle.circle(20,180)
if lives==4:
turtle.right(90)
turtle.pensize(15)
turtle.color('white')
turtle.forward(120)
if lives==3:
turtle.pensize(15)
turtle.color('white')
turtle.backward(60)
turtle.left(135)
turtle.forward(60)
if lives==2:
turtle.pensize(15)
turtle.color('white')
turtle.backward(60)
turtle.left(90)
turtle.forward(60)
turtle.backward(60)
if lives==1:
turtle.pensize(15)
turtle.color('white')
turtle.left(135)
turtle.forward(60)
turtle.left(45)
turtle.forward(60)
elif lives==0:
turtle.pensize(15)
turtle.color('white')
turtle.backward(60)
turtle.right(90)
turtle.forward(60)
style = ('Courier', 25, 'italic')
turtle.penup()
turtle.goto(0,-240)
turtle.pendown()
turtle.color('yellow')
turtle.write("\n!! GAME OVER !!", font=style, align='center')
turtle.pu()
turtle.goto(0,-280)
turtle.write("\n!! BETTER LUCK NEXT TIME !! ", font=style, align='center')
turtle.pu()
turtle.goto(0,-320)
turtle.write("\n: The word was :", font=style, align='center')
turtle.color('black')
turtle.pu()
turtle.goto(0,-360)
turtle.write(str(show), font=style, align='center')
print('GAME OVER - BETTER LUCK NEXT TIME\nThe word was',show)
option=input('\nDo you want to play again :\nY/N : ')
if option.lower()=='y':
turtle.reset()
play=True
else:
play=False