池塘夜降彩色雨代码数据结构课程设计Word下载.docx
《池塘夜降彩色雨代码数据结构课程设计Word下载.docx》由会员分享,可在线阅读,更多相关《池塘夜降彩色雨代码数据结构课程设计Word下载.docx(21页珍藏版)》请在冰点文库上搜索。
intrain_wind;
intrain_len;
intkey;
intbig;
intm;
intcurx;
intcury;
intthunder[6][2]={{10,20},{-10,0},{10,20},{-25,-25},{15,0},{0,-15}};
/**********定义结构*************/
structrainDrop*head;
/*********雨滴雨圈雷电数据结构体链表**********/
structrainDrop
{
intstartX,curX,startY,curY;
intflag;
intendX;
intendY;
intrainColor;
intstatus;
intflagR;
intcurR;
intthunderX1,thunderX2,thunderY1,thunderY2;
inta,b;
structrainDrop*next;
};
/*********初始化画布**********/
/*********参数void**********/
/*********return无**********/
voidinitgraphics(void)
intgmode,gdriver;
gdriver=DETECT;
initgraph(&
gdriver,&
gmode,"
"
);
}
/*********创建初始化头结点**********/
/*********返回指针p**********/
structrainDrop*creatDrop(void)
structrainDrop*p;
p=(structrainDrop*)malloc(sizeof(structrainDrop));
p->
startX=random(640);
startY=random(430);
flag=430+rand()%50;
curX=p->
startX-(rain_wind*5);
curY=p->
startY+rain_len;
rainColor=random(15);
status=0;
flagR=random(10);
curR=random
(2);
thunderX1=random(300);
thunderY1=random(20);
next=NULL;
return(p);
/*********重新生成链表数据**********/
voidrecreatDrop(structrainDrop*p)
curR=random(3);
/*********创建整个链表**********/
voidcreatRain(void)
structrainDrop*p1,*p2;
/*定义两个指针*/
inti;
p1=p2=creatDrop();
head=p1;
/*赋值头指针*/
for(i=0;
i<
rain_Num;
i++)/*循环创建整个雨滴链表*/
{
p2=creatDrop();
p1->
next=p2;
p1=p2;
}
/*********生成下一个雨滴的坐标位置**********/
voidupdateRainLineData(structrainDrop*p)
{
if(big==2)/*加速为2个雨滴距离下落*/
p->
startX=p->
curX;
startY=p->
curY;
if(big==1)/*加速为一个雨滴的距离下落*/
else/*正常速度下落*/
/********雨雪选择函数***********/
selectWinter()
m=1;
selectSumm()
m=6;
/********分屏函数***********/
splitScreen(structrainDrop*p)
curx=p->
curX/200;
cury=p->
curY/110;
switch(curx)
case0:
switch(cury)
{
case0:
case1:
selectSumm();
break;
case2:
selectWinter();
case3:
}break;
case1:
case2:
case3:
switch(cury)
{
case0:
case1:
case2:
case3:
}break;
}
/********画出彩色雨滴***********/
voiddrawRainLine(structrainDrop*p,intm)
{
setcolor(p->
rainColor);
/*将雨滴赋予颜色*/
if(m>
=3&
&
m<
=11)/*月份*/
line(p->
startX,p->
startY,p->
curX,p->
curY);
/*画雨滴*/
else/*雪*/
setcolor(WHITE);
setfillpattern(2,WHITE);
sector(p->
curY,0,360,5,4);
/********清除上一滴的雨滴***********/
voidclearRainLine(structrainDrop*p,intm)
setcolor(BLACK);
/*将雨滴赋予黑色*/
=11)
else
setfillpattern(2,BLACK);
sector(p->
/********雨滴入数的声音***********/
getsound()
intfreq;
for(freq=300;
freq<
5000;
freq+=50)
sound(freq);
delay(400);
nosound();
/*********雷电声音**********/
thunderesound()
for(freq=1000;
2000;
delay(5000);
/*********下雨**********/
voidrainDropDown(structrainDrop*p,intm)
if(p->
curY>
=p->
flag)
clearRainLine(p,m);
status=1;
getsound();
else
updateRainLineData(p);
drawRainLine(p,m);
/********雨圈生长变大***********/
voidupdateRainCircleData(structrainDrop*p)
curR+=1;
/*********画出雨圈**********/
voiddrawRainCircle(structrainDrop*p)
ellipse(p->
curY,0,360,10+p->
curR*3,p->
curR);
/*******清理雨圈************/
voidclearRainCircle(structrainDrop*p)
setfillpattern(2,BLUE);
/*******入水水圈生成结束重新刷新雨点************/
voidfallToWater(structrainDrop*p)
curR>
flagR)
clearRainCircle(p);
recreatDrop(p);
updateRainCircleData(p);
drawRainCircle(p);
/********画出雷电***********/
intdrawthurder(structrainDrop*p)
inti,j,k,x,y;
setbkcolor(BLACK);
setcolor(WHITE);
for(k=0;
k<
2;
k++)
x=random(100);
y=random(100);
thunderX1+=x;
thunderY1+=y;
a=p->
thunderX1;
b=p->
thunderY1;
for(i=0;
6;
i++)
for(j=0;
j<
j++)
setfillpattern(0,WHITE);
thunderX2=p->
thunderX1-thunder[i][j];
j++;
thunderY2=p->
thunderY1+thunder[i][j];
line(p->
thunderX1,p->
thunderY1,p->
thunderX2,p->
thunderY2);
thunderX1=p->
thunderX2;
p->
thunderY1=p->
thunderY2;
floodfill(p->
a-3,p->
b+12,WHITE);
setfillpattern(0,0);
bar(p->
a-20,p->
b-10,p->
a+40,p->
b+40);
}
/*******函数实现释放链表收起画布***********/
voidrainfree(void)
charmark;
structrainDrop*p,*q;
p=head;
while(p!
=NULL)
q=p;
p=p->
next;
free(q);
closegraph();
/********键盘控制***********/
keyboardCon(structrainDrop*p)
key=bioskey(0);
if(key==LEFT)
rain_wind+=1;
if(key==TWO)
if(key==RIGHT)
rain_wind-=1;
if(key==DOWN)
rain_len-=1;
if(key==UP)
rain_len+=1;
if(key==SPACE)
rainfree();
exit(0);
if(key==PLUS&
big<
2)
big+=1;
if(key==JIAN)
big-=1;
if(key==ONE)
splitScreen(p);
if(key==THREE)
m=6;
/********软件介绍信息***********/
output()
outtextxy(100,10,"
Pondnightrainfallcolor---thankyou!
"
outtextxy(500,400,"
09060641"
/********河水***********/
river()
setfillpattern(0,BLUE);
bar(0,440,640,500);
/********下雨***********/
voidrain(intm)
while(!
(key==ESC))
keyboardCon(p);
kbhit())
if(p==NULL)
p=head;
else
{
if(p->
status==0)
rainDropDown(p,m);
else
fallToWater(p);
delay(rain_v);
output();
if(key==ENTER)
drawthurder(p);
thunderesound();
key=NULL;
/********软件开始简介***********/
voidIntroduction()
printf("
******************************\n"
printf("
Pondnightrainfallcolor!
\n"
\tclass:
09060641\n"
/*********过滤函数*************/
filter()
i=0;
while(i>
=6)
if(rain_Num<
0&
rain_Num>
50)
printf("
error\nNotePleaseenterlessthanfiftygreaterthanzero\nrain_num:
scanf("
%d"
&
rain_Num);
i+=1;
if(rain_v<
rain_v>
10)
error\nNotePleaseenterlessthanfiftygreaterthanzero\nrain_v:
rain_v);
if(rain_len<
rain_len>
error\nNotePleaseenterlessthantengreaterthanzero\nrain_len:
rain_len);
if(rain_wind<
rain_wind>
error\nNotePleaseenterlessthantengreaterthanzero\nrain_wind:
rain_wind);
if(m<
m>
error\nNotePleaseenterlessthan12greaterthanzero\nmonth:
m);
/********全局变量的输入及其判定***********/
voidinput()
rain_num:
\nNotePleaseenterlessthanfiftygreaterthanzero"
scanf("
rain_v:
\nNotePleaseenterlessthanfiftygreaterthanzero"
rain_wind:
\nNotePleaseenterlessthantengreaterthanzero"
rain_length:
themonthoftheyear:
\nNotePleaseenterlessthan12greaterthan1"
filter();
big=1;
/********程序入口主函数**********/
main()
Introduction();
input();
initgraphics();
creatRain();
river();
rain(m);