这是我前几天给一学生的 #include<stdio.h> #include<graphics.h> #include<conio.h> #include<stdlib.h> #include<bios.h> void balldraw()/*初始化圆*/ { setcolor(RED); circle(320,240,5); setfillstyle(1,RED); floodfill(317,237,RED); } main() { int driver=VGA,gmode=VGAHI,x1,x2,x3,x4; char *buf; initgraph(&driver,&gmode,""); balldraw(); x1=imagesize(315,235,325,245); buf=malloc(x1); getimage(315,235,325,245,buf); while(1) { while(bioskey(1)==0); x2=bioskey(0);/*获得键盘输入*/ x2=x2&0xff?0:x2>>8; if(x2==72) /*是上键*/ { for(a3=0;a3<23;a3++) { clearviewport(); putimage(315,235-a3*10,buf,XOR_PUT); delay(1000000000000000000000); } clearviewport(); putimage(315,235,buf,COPY_PUT); } if(x2==80) /*是下键*/ { for(a3=0;a3<=22;a3++)
{ clearviewport(); putimage(315,240+a3*10-5,buf,COPY_PUT); delay(1000000000000000000000); } clearviewport(); putimage(315,235,buf,COPY_PUT); } if(x2==75) /*是左键*/ { for(a3=0;a<=31;a3++) { clearviewport(); putimage(320+a3*10-5,235,buf,XOR_PUT); delay(10000000000000000000000000); } clearviewport(); putimage(315,235,buf,COPY_PUT); }
if(a2==77) /*是右键*/ { for(a3=0;a3<=31;a3++) { clearviewport(); putimage(320-a3*10-5,235,buf,COPY_PUT); delay(100000000000000000000000000000); } clearviewport(); putimage(315,235,buf,COPY_PUT); } if(a2==13) /*是回车键*/ exit(0); } }