人月團圓趣味程式:用C實現的愛情宣言(轉)

ba發表於2007-08-15
人月團圓趣味程式:用C實現的愛情宣言(轉)[@more@]祝有情人團圓

#include "stdio.h"
#include "graphics.h"
#include "time.h"
#include "math.h"
#define N 2
#define TIME 0.8/*微粒的的運動時間,TIME/步,每一步長為25個單位*/
void *buf[N];
struct
{
int x,y;

} lizi[]={{0,0},{75,75}};

void alter_place_lizi(int *x,int *y,int key)/*根據隨機方向改變粒子的方位*/
{


switch(key)
{case 0:
case 1:
case 2:*x-=25;break;
case 4:
case 5:
case 6:*x+=25;break;
}
switch(key)
{ case 0:
case 7:
case 6:*y-=25;break;
case 2:
case 3:
case 4:*y+=25;break;
}
if(*x<0) *x=0;
if(*x>250) *x=250;
if(*y<0) *y=0;
if(*y>250) *y=250;
}

void make_graphics()/*畫方框*/
{int i,j,driver=VGA,mode=VGAHI;
initgraph(&driver,&mode,"");
setbkcolor(YELLOW);
cleardevice();
setcolor(LIGHTRED);
setlinestyle(0,0,1);
for(i=0;i<=10;i++)
line(0,25*i,250,25*i);
for(i=0;i<=10;i++)
line(25*i,0,25*i,250);
}void make_circle(int x,int y,int n)/*根據提供的離子所在方位畫圓*/
{
int size;
setcolor(LIGHTRED);
setlinestyle(0,0,1);
setfillstyle(1,10);
circle(x+25/2,y+25/2,25/2);
floodfill(x+25/2,y+25/2,12);
size=imagesize(x,y,x+25,y+25);
buf[n]=(void *)malloc(size);/*儲存每一個圓*/
}


void sport(int *x,int *y)/*粒子的運動*/
{
time_t starttime,endtime;
int seed=0,i,j;
int key;
char s[300];
int t=1;
srand(seed);


/*儲存現場圖形*/
for(i=0;i getimage(x,y,x+25,y+25,buf);
cleardevice();/*清除*/
setbkcolor(BLUE);
cleardevice();
setviewport(50, 50, 590, 430, 1); /*定義一個圖形視窗*/
setfillstyle(1, 2); /*綠色以實填充*/
setcolor(YELLOW);
rectangle(0, 0,590, 230);
floodfill(50, 50, 14);
setcolor(12);
settextstyle(1, 0, 8); /*三重筆劃字型, 水平放大8倍*/
outtextxy(20, 20, "I miss you");
setcolor(11);
settextstyle(1, 0, 4); /*三重筆劃字型, 水平放大4倍*/
outtextxy(100, 100, "where are you");
time(&starttime);
time(&endtime);
for(;difftime(endtime,starttime)<=2.0;time(&endtime));
setbkcolor(YELLOW);
cleardevice();
setcolor(LIGHTRED);
setlinestyle(0,0,1);
while(t)
{
if(fabs(x[0]-x[1])==25&&fabs(y[0]-y[1])==25)
{for(i=0;i {key=rand()%8;
alter_place_lizi(&x,&y,key);
}
}

else if(fabs(x[0]-x[1])==25||fabs(y[0]-y[1])==25)
{key=rand()%8;
for(i=0;i alter_place_lizi(&x,&y,key);t++;
}
else
{for(i=0;i {key=rand()%8;
alter_place_lizi(&x,&y,key);
}
}

for(i=0;i putimage(x,y,buf,COPY_PUT);

/*介面維持0.5秒鐘*/
time(&starttime);
time(&endtime);
for(;difftime(endtime,starttime)<=TIME;time(&endtime));


for(i=0;i getimage(x,y,x+25,y+25,buf);
cleardevice();
switch(t)
{case 1:setcolor(t);
settextstyle(1, 0, 2); /*三重筆劃字型, 水平放大4倍*/
outtextxy(t, t, "I am tired to look after you"); delay(1e10);
break;

case 2:setcolor(t);
settextstyle(1, 0, 2); /*三重筆劃字型, 水平放大4倍*/
outtextxy(t, t, "could you wait for me please?");delay(1e10);
break;
case 3:setcolor(t);
settextstyle(1, 0, 2); /*三重筆劃字型, 水平放大4倍*/
outtextxy(t, t, "I can not catch up with you");delay(1e10); break;
case 4:setcolor(t);
settextstyle(1, 0, 2); /*三重筆劃字型, 水平放大4倍*/
outtextxy(t, t, "you walk so quckily");delay(1e10); break;
case 5:setcolor(t);
settextstyle(1, 0, 2); /*三重筆劃字型, 水平放大4倍*/
outtextxy(t, t, "I will not give up and I believe I can keep up with you one day");delay(1e10); break;
case 6:setcolor(t);
settextstyle(1, 0, 2); /*三重筆劃字型, 水平放大4倍*/
outtextxy(t, t, "I can not help stoping as result of your beauty");delay(1e10); break;
default:setcolor(t);
settextstyle(1, 0, 5); /*三重筆劃字型, 水平放大4倍*/
outtextxy(t-3, t-3, "I will go with you forever");
}

}

}
main()
{time_t starttime,endtime;
int i,j;
int x[N],y[N],t[N];
make_graphics();

for(i=0;i make_circle(lizi.x,lizi.y,i);
time(&starttime);
time(&endtime);
for(;difftime(endtime,starttime)<=1.0;time(&endtime));
for(i=0;i{x=lizi.x;
y=lizi.y;

}
sport(x,y);
}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10617731/viewspace-957857/,如需轉載,請註明出處,否則將追究法律責任。

相關文章