-
Notifications
You must be signed in to change notification settings - Fork 1
/
HANGMAN_V_1.0.CPP
244 lines (212 loc) · 4.01 KB
/
HANGMAN_V_1.0.CPP
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <graphics.h>
#include <string.h>
int i;
char j[3];
int body();
int wrong1();
int wrong2();
int wrong3();
int wrong4();
int wrong5();
int wrong6();
void words();
void rules()
{
printf("1.A Hint will be given and you have to guess the word\n");
printf("2.You will have 6 lives.\n");
printf("3.You should only enter capital letters");
printf("\nPress p to play game");
gets(j);
if(strcmp(j,"p")==0)
{
words();
}
}
int hints(int r)
{
printf("\tHINT:");
if(r==0)
printf("Gadget");
else if(r==1)
printf("Fruit");
else if(r==2)
printf("Search Engine");
else if(r==3)
printf("C");
else if(r==4)
printf("Knowledge");
else if(r==5)
printf("Campus");
else
printf("Color");
return r;
}
void words()
{
srand(time(NULL));
char words[][50]={"MOBILE","APPLE","GOOGLE","LANGUAGE","BOOK","PULCHOWK","BLUE"};
int random=rand()%7;
int numlives=6, numcorrect=0, up=3, oldcorrect=0, quit=0;
int wordlength=strlen(words[random]);
int letterguessed[10]={0,0,0,0,0,0,0,0,0,0};
char guess[20] ,letterentered;
body();
printf("word length=%d\t",wordlength);
hints(random);
printf("\n\n");
for(i=0; i<wordlength; i++)
printf("_ ");
while(numcorrect<wordlength)
{
printf("\nEnter a guess letter:");
gets(guess);
if(strcmp(guess,"quit")==0)
{
quit=1;
break;
}
letterentered=guess[0];
//printf("Entered Letter:%c\n",letterentered);
printf("\033[%dA\033[%dL",up);
oldcorrect=numcorrect;
for (i=0;i<wordlength;i++)
{
if (letterguessed[i]==1)
{
continue;
}
if (letterentered == words[random][i])
{
letterguessed[i]=1;
numcorrect++;
}
}
printf("\n");
for(i=0;i<wordlength; i++){
if(letterguessed[i]==0)
printf("_ ");
else
printf("%c ",words[random][i]);
}
if(oldcorrect==numcorrect)
{
numlives--;
}
// printf("\nLives Left:%d",numlives);
if(numlives==5)
{
body();
numlives= wrong1();
}
if(numlives==4)
{
body();
numlives= wrong1();
numlives= wrong2();
}
if(numlives==3)
{
body();
numlives=wrong1();
numlives=wrong2();
numlives= wrong3();
}
if(numlives==2)
{
body();
numlives=wrong1();
numlives=wrong2();
numlives=wrong3();
numlives= wrong4();
}
if(numlives==1)
{
body();
numlives=wrong1();
numlives=wrong2();
numlives=wrong3();
numlives=wrong4();
numlives= wrong5();
}
if(numlives==0)
{
body();
numlives=wrong1();
numlives=wrong2();
numlives=wrong3();
numlives=wrong4();
numlives=wrong5();
numlives= wrong6();
moveto(500,100);
settextstyle(SANS_SERIF_FONT,0,0);
setusercharsize(1,1,2,1);
outtext("HANGED");
break;
}
}
if (quit==1)
printf("\nYOU LEFT THE GAME");
if(numlives>0&&strcmp(guess,"quit")!=0)
{
moveto(500,100);
settextstyle(SANS_SERIF_FONT,0,0);
setusercharsize(1,1,2,1);
outtext("YOU WON");
}
}
int main()
{
int gd,gm;
gd=DETECT;
initgraph (&gd,&gm,"C:\\TURBOC3\\BGI");
printf("Press p to play game and r for rules");
gets(j);
if(strcmp(j,"p")==0)
words();
else if(strcmp(j,"r")==0)
rules();
getch();
closegraph();
return 0;
}
int body()
{
line (500,80,600,80); // horizontal line
line (500,80,500,180); // vertical line
line (530,80,500,110); // slanted line
line (600,80,600,90); // small vertical line
line (500,180,630,180); // base line
}
int wrong1() //function to create head
{
circle(600,100,10);
return 5;
}
int wrong2() //function to create body
{
line(600,110,600,140);
return 4;
}
int wrong3() //function to create hand
{
line(600,120,580,130);
return 3;
}
int wrong4() //function to create other hand
{
line(600,120,620,130);
return 2;
}
int wrong5() //function to create leg
{
line(600,140,580,160);
return 1;
}
int wrong6() //function to create other leg
{
line(600,140,620,160);
return 0;
}