-
Notifications
You must be signed in to change notification settings - Fork 1
/
Catch-The-Blocks
95 lines (83 loc) · 1.16 KB
/
Catch-The-Blocks
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
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
int main()
{
int gd = DETECT,gm;
char c, buff[15];
int score=0,o=0,miss=0;
int x=400,y=200,i=1,k=0,ya=275,yb=125;
int ch=ya,ch1=yb;
int x1=x+320;
int timer,speed;
initgraph(&gd, &gm, "C:\\TC\\BGI");
setbkcolor(4);
printf("Game length (seconds) : ");
scanf("%d",&timer);
printf("Game speed (default 10) : ");
scanf("%d",&speed);
timer=timer*100;
while(i<timer)
{
cleardevice();
if(miss==50)
goto sos;
x=x-speed+2;
if(x<0)
{
x=640;
if(rand()%2==0)
ch=ya;
else
ch=yb;
}
if(x==40)
{{if((ch>y-70)&&(ch<y+20))
score++;
else
miss++;
}
}
setcolor(14);
rectangle(x,ch,x+50,ch+50);
x1=x1-speed+2;
if(x1<0)
{
x1=640;
if(rand()%2==0)
ch1=ya;
else
ch1=yb;
}
setcolor(14);
rectangle(x1,ch1,x1+50,ch1+50);
if(x1==40)
{{if((ch1>y-70)&&(ch1<y+20))
score++;
else
miss++;
}
}
if(kbhit()!=0)
{c=getch();
if(c=='P')
y=(y+speed+2)%640;
if(c=='H')
{
y=y-speed-2;
if(y<0) y=640;
}
}
circle(20,y,20);
delay(10);
i++;
}
sos:closegraph();
printf("Enter 1 to know your score : ");
scanf("%d",&o);
if(o==1)
printf("Your score is %d out of %d.",score,score+miss);
getch();
return 0;
}