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
| #include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#include <iostream.h>
void draw(int x,int y,int c);
int main (void)
{
int gd=DETECT,gm;
int x=0,y=404,speed=-20;
char ch;
initgraph(&gd,&gm,"");
outtextxy(200,20,"press ESC to finish");
do
{
draw (x,y,ch);
delay (500);
draw (x,y,0);
if(rand()%2)
{
x+=-speed;
}
else
{
if (y+85>getmaxy()&&(x>10))
{
speed=0;
y=405;
}
if (x<140) y+=speed;
else y-=speed;
}
if (kbhit())
ch=getch();
}
while (ch!=27);
closegraph();
return 0;
}
void draw (int xx,int yy,int c)
{
setcolor (c);
setfillstyle (1,c);
bar (xx-30,yy-5,xx+30,yy+5);
line (0,405,640,405);
} |