-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCode
331 lines (309 loc) · 5.65 KB
/
Code
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
char ch1,ch2,ch='a';
int m,n;
int gta=35;
void direc();
void right1();
void right2();
void down1();
void down2();
void left1();
void left2();
void up1();
void up2();
void draw();
void check(int op);
void win1();
void win2();
void name();
void menu();
void help();
void about();
void lvl();
struct cood
{
int x;
int y;
}head1,tail1,head2,tail2;
char a[200][200];
char p1[20],p2[20];
void main()
{
int gd=DETECT,gm,i,j;
char cho;
initgraph(&gd,&gm,"C:\\Turboc3\\BGI");
head1.x=129;
head1.y=239;
tail1.x=129;
tail1.y=239;
head2.x=509;
head2.y=239;
tail2.x=509;
tail2.y=239;
for(i=0;i<200;i++)
{
for(j=0;j<200;j++)
{
a[i][j]='a';
}
}
setbkcolor(BLUE);
setcolor(YELLOW);
rectangle(5,5,634,474);
rectangle(6,6,633,473);
settextstyle(TRIPLEX_SCR_FONT,HORIZ_DIR,7);
outtextxy(200,250,"DON'T CROSS THE LINE");
delay(2500);
cleardevice();
menu();
cleardevice();
rectangle(5,5,634,474);
rectangle(6,6,633,473);
rectangle(119,64,519,414);
setlinestyle(SOLID_LINE, 0, 2);
right1();
left2();
draw();
getch();
closegraph();
}
void direc(char ele)
{
if(ele=='d' && ch1!='a'){
right1();
ch1='d';}
else if(ele=='s' && ch1!='w'){
down1();
ch1='s'; }
else if(ele=='a' && ch1!='d'){
left1();
ch1='a';}
else if(ele=='w' && ch1!='s'){
up1();
ch1='w'; }
else if(ele=='j' && ch2!='l'){
left2();
ch2='j';}
else if(ele=='k'&& ch2!='i'){
down2();
ch2='k';}
else if(ele=='l' && ch2!='j'){
right2();
ch2='l'; }
else if(ele=='i'&& ch2!='k'){
up2();
ch2='i';}
else if(ele=='y')
exit(0);
}
void right1()
{
head1.x=head1.x+1;
check(2);
m=4;
}
void right2()
{
head2.x=head2.x+1;
check(6);
n=4;
}
void left1()
{
head1.x=head1.x-1;
check(4);
m=2;
}
void left2()
{
head2.x=head2.x-1;
check(8);
n=2;
}
void down1()
{
head1.y=head1.y+1;
check(1);
m=3;
}
void down2()
{
head2.y=head2.y+1;
check(5);
n=3;
}
void up1()
{
head1.y=head1.y-1;
check(3);
m=1;
}
void up2()
{
head2.y=head2.y-1;
check(7);
n=1;
}
void draw()
{
char ch;
ch1='d';
ch2='j';
while(1)
{
setcolor(CGA_YELLOW);
circle(head1.x,head1.y,0.5);
setcolor(CGA_RED);
circle(head2.x,head2.y,0.5);
if(kbhit())
{
ch=getch();
direc(ch);
}
direc(ch2);
direc(ch1);
delay(gta);
}
}
void check(int op)
{
int i,j,k,l;
if(head1.x<119||head1.x>519||head1.y<64||head1.y>414)
{
win2();
}
if(head2.x<119||head2.x>519||head2.y<64||head2.y>414)
{
win1();
}
i=(int)(head1.x-50)/2;
j=(int)(head1.y-50)/2;
k=(int)(head2.x-50)/2;
l=(int)(head2.y-50)/2;
switch(op)
{
case 1:if(a[j+1][i]=='b'){win2();}break;
case 2:if(a[j][i+1]=='b'){win2();}break;
case 3:if(a[j-1][i]=='b'){win2();}break;
case 4:if(a[j][i-1]=='b'){win2();}break;
case 5:if(a[l+1][k]=='b'){win1();}break;
case 6:if(a[l][k+1]=='b'){win1();}break;
case 7:if(a[l-1][k]=='b'){win1();}break;
case 8:if(a[l][k-1]=='b'){win1();}break;
}
a[j][i]='b';
a[l][k]='b';
}
void win1()
{
delay(3000);
cleardevice();
rectangle(5,5,634,474);
rectangle(6,6,633,473);
outtextxy(200,200,"PLAYER 1 WINS!!!");
outtextxy(400,400,"press any key to return...");
getch();
closegraph();
main();
}
void win2()
{
delay(3000);
cleardevice();
rectangle(5,5,634,474);
rectangle(6,6,633,473);
outtextxy(200,200,"PLAYER 2 WINS!!!");
outtextxy(400,400,"press any key to return...");
getch();
closegraph();
main();
}
void menu()
{
char f;
setbkcolor(BLUE);
setcolor(YELLOW);
rectangle(5,5,634,474);
rectangle(6,6,633,473);
settextstyle(TRIPLEX_SCR_FONT, HORIZ_DIR,1);
outtextxy(70,70,"DON'T CROSS THE LINE");
outtextxy(250,200,"1) NEW GAME");
outtextxy(250,220,"2) LEVEL");
outtextxy(250,240,"3) HELP");
outtextxy(250,260,"4) ABOUT");
outtextxy(250,280,"5) EXIT");
f=getch();
switch(f)
{
case '1':break;
case '3':help();menu();break;
case '4':about();menu();break;
case '2':lvl();menu();break;
case '5':exit(0);
default:menu();
}
}
void help()
{
int FONT;
cleardevice();
rectangle(5,5,634,474);
rectangle(6,6,633,473);
gotoxy(30,2);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(70,70,"RULES:");
settextstyle(FONT,HORIZ_DIR,3);
outtextxy(205,100,"DO NOT TOUCH THE BOUNDARY LINE");
outtextxy(205,130,"DO NOT TOUCH THE OPPONENT");
outtextxy(205,160,"DO NOT OVERLAP ON YOUR OWN PATH");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(70,250,"CONTROLS:");
settextstyle(FONT,HORIZ_DIR,3);
outtextxy(205,280,"W,A,S,D KEYS FOR PLAYER 1");
outtextxy(205,310,"I,J,K,L KEYS FOR PLAYER 2");
outtextxy(400,400,"press any key to return...");
getch();
cleardevice();
}
void about()
{
int FONT;
cleardevice();
rectangle(5,5,634,474);
rectangle(6,6,633,473);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(265,50,"!!!DISCLAIMER!!!");
settextstyle(FONT,HORIZ_DIR,3);
outtextxy(75,100,"THE CONCEPT OF THIS GAME IS INSPIRED FROM A MINI GAME IN GTA 5");
outtextxy(300,280,"THIS GAME IS CREATED BY,");
outtextxy(300,300,"THE STUDENTS OF IT SECTION-B");
outtextxy(340,320,"ABHILASH - 16241A1268");
outtextxy(340,340,"MUZAMMIL - 16241A1293");
outtextxy(340,360,"ROHIT - 16241A1299");
outtextxy(400,400,"press any key to return...");
getch();
cleardevice();
}
void lvl()
{
char GTA5;
cleardevice();
rectangle(5,5,634,474);
rectangle(6,6,633,473);
outtextxy(70,70,"SELECT YOUR LEVEL");
outtextxy(250,200,"1) EASY");
outtextxy(250,220,"2) MEDIUM");
outtextxy(250,240,"3) DIFFUCULT");
GTA5=getch();
switch(GTA5)
{
case '1':gta=gta+10;break;
case '2':gta=gta;break;
case '3':gta=gta-10;break;
default:gta=gta;
}
cleardevice();
}