赛迪网 > IT技术 源码直通车 > 文章
  IT资讯搜索
 
IT产品搜索
[程序开发][网管世界][网络安全][数据库技术]
[操作系统][嘉宾聊天·在线访谈][活动集锦]
[精彩专题][Symantec专区][订阅IT技术周刊]
[开发论坛][网管论坛][安全论坛][数据库论坛]
[操作系统论坛][Sybase专区][IBM dW技术专区]
[病毒求助][病毒与漏洞播报][文档·源码下载]

人月团圆趣味程序:用C实现的爱情宣言

发布时间:2006.01.10 10:52     来源:赛迪论坛    作者:Sabine

祝有情人团圆

#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[i],y[i],x[i]+25,y[i]+25,buf[i]);
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[i],&y[i],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[i],&y[i],key);t++;
}
else
{for(i=0;i {key=rand()%8;
alter_place_lizi(&x[i],&y[i],key);
}
}

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

/*界面维持0.5秒钟*/
time(&starttime);
time(&endtime);
for(;difftime(endtime,starttime)<=TIME;time(&endtime));


for(i=0;i getimage(x[i],y[i],x[i]+25,y[i]+25,buf[i]);
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[i].x,lizi[i].y,i);
time(&starttime);
time(&endtime);
for(;difftime(endtime,starttime)<=1.0;time(&endtime));
for(i=0;i{x[i]=lizi[i].x;
y[i]=lizi[i].y;

}
sport(x,y);
}


[ 发表评论 ] 字体[  ] [ 打印 ] [ 进入博客 ] [ 进入论坛 ]  [ 推荐给朋友 ]
  相关文章
· 对C# 2.0中匿名方法的种种怀疑分析 (01-10) · Java理论与实践:再谈Urban性能之传言 (11-15)
· 校园爱情十大模式 (11-11) · 专家教您如何在C语言中巧用正则表达式 (05-19)
· 编程初级班:C语言程序设计入门系列之二 (05-19) · 教您在C/C++中如何构造通用的对象链表 (05-17)
· 与C/C++指针相似的C#代表元及事件触发 (05-17) · 如何在Linux桌面上搭建C/C++IDE开发环境 (05-17)
· 初学者必备:教你理解复杂的C/C++声明 (05-13) · 编程秘籍篇:C语言高效编程的四大绝招 (05-13)
  客户需求反馈表
* 姓  名:
更多资料  了解方案  认识厂商
* 单位名称:
* 联系电话:
* 电子邮件:
  赛迪推荐  
  手机·资费 ·新品·导购·评测·手机资费·宽带
手机搜索  诺基亚 N73 MOTO Z6
  IT产品 ·笔记本·台式机·服务器·打印·投影
IT产品搜索 
  IT技术 ·开发·网管·安全·数据库·操作系统
  信息化 ·热点·专题·访谈·周刊·方案案例
[政务][电信][金融][农业][制造业][中小企业]
[CIO][ERP][协同][IT管理][中间件][电子商务]
[政策][地方][专家][评估][辞典][博客][社区]
· 专题:一路畅通构想曲——让出行不再遭遇堵车
· CIO工作亲历:企业ERP选型不能忽视"选人关"
· 综述:信息化建设给中国监狱带来的各种变化
· 金融业风险管理和法规遵从有五点需考虑的因素
· 保险业CIO关注:该如何建立统一高效的CRM体系
· 调查显示:多数CIO对IT规划仍存在困惑和误解
  博客·论坛 ·曾剑秋·项立刚·Java学习·网管