跳动的小球

王朝other·作者佚名  2008-06-01
窄屏简体版  字體: |||超大  

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

#include <math.h>

#define ESC 0x1b;

#define MAXNUM 100

main()

{ char *buf;

char sign,sign1[MAXNUM] = {1},sign2[MAXNUM] = {1};

int i,size,a;

int x[MAXNUM],y[MAXNUM],r[MAXNUM][MAXNUM];

int gd = DETECT,gm;

clrscr();

printf("please input the number of ball you want:\n");

scanf("%d",&a);

registerbgidriver(EGAVGA_driver);

initgraph(&gd,&gm,"");

setcolor(YELLOW);

setfillstyle(SOLID_FILL,9);

rectangle(0,0,getmaxx(),getmaxy());

rectangle(1,1,getmaxx()-1,getmaxy()-1);

bar(2,2,getmaxx()-2,getmaxy()-2);

for(i = 8;i >=0;i --)

{ setcolor(i + 7);

circle(11,getmaxy() - 11,i);

}

size = imagesize(2,getmaxy() - 20,20,getmaxy() - 2);

buf = malloc(size);

getimage(2,getmaxy()-20,20,getmaxy() - 2,buf);

for(i = 8;i >= 0;i --)

{ setcolor(9);

circle(11,getmaxy() - 11,i);

}

randomize();

for(i = 0;i < a;i ++)

{ x[i] = random(600) + 20;

y[i] = random(400) + 32;

}

while(1)

{ if(kbhit())

{ sign = getch();

if(sign == 0x1b)

{ free(buf);

break;

}

}

else

{

for(i = 0;i < a;i ++){

putimage((sign1[i] == 1 ? x[i] ++ : x[i] --),

(sign2[i] == 1 ? y[i] ++ : y[i] --),buf,COPY_PUT);

if(x[i] > getmaxx() - 21)

sign1[i] = 0;

if(x[i] < 3) sign1[i] = 1;

if(y[i] > getmaxy() - 21)

sign2[i] = 0;

if(y[i] < 3) sign2[i] = 1;}

}

}

free(buf);

closegraph();

return 0;

}



right"(出处:清风软件下载学院)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航