资源描述
/**********包涵到头文献*********/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <dos.h>
#include <graphics.h>
#include <bios.h>
/**********宏定义*********/
/*********键盘控制 键盘扫描码**********/
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define L_SHEFT 0x01
#define SPACE 0x3920
#define LOWERF 0x2166
#define UPPERF 0x2146
#define LOWERA 0x1e61
#define UPPERA 0x1e41
#define LOWERQ 0x1071
#define UPPERQ 0x1051
#define ENTER 0x1c0d
#define ONE 0x4f31
#define TWO 0x5032
#define THREE 0x5133
#define FOUR 0x4b34
#define FIVE 0x4c35
#define SIX 0x4d36
#define SEVEN 0x4737
#define EIGHT 0x4838
#define NINE 0x4939
#define O 0x5230
#define PLUS 0x4e2b
#define JIAN 0x4a2d
/**********全局变量*********/
int rain_Num;
int rain_v;
int rain_wind;
int rain_len;
int key;
int big;
int m;
int curx;
int cury;
int thunder[6][2]={{10,20},{-10,0},{10,20},{-25,-25},{15,0},{0,-15}};
/**********定义构造*************/
struct rainDrop *head;
/*********雨滴 雨圈 雷电数据 构造体链表**********/
struct rainDrop
{
int startX,curX,startY,curY;
int flag;
int endX;
int endY;
int rainColor;
int status;
int flagR;
int curR;
int thunderX1,thunderX2,thunderY1,thunderY2;
int a,b;
struct rainDrop *next;
};
/*********初始化画布**********/
/*********参数void**********/
/*********return无**********/
void initgraphics(void)
{
int gmode,gdriver;
gdriver=DETECT;
initgraph(&gdriver,&gmode,"");
}
/*********创立初始化头结点**********/
/*********返回指针p**********/
struct rainDrop *creatDrop(void)
{
struct rainDrop *p;
p=(struct rainDrop *)malloc(sizeof(struct rainDrop));
p->startX=random(640);
p->startY=random(430);
p->flag=430+rand()%50;
p->curX=p->startX-(rain_wind*5);
p->curY=p->startY+rain_len;
p->rainColor=random(15);
p->status=0;
p->flagR=random(10);
p->curR=random(2);
p->thunderX1=random(300);
p->thunderY1=random(20);
p->next=NULL;
return(p);
}
/*********重新生成链表数据**********/
void recreatDrop(struct rainDrop *p)
{
p->startX=random(640);
p->startY=random(430);
p->flag=430+rand()%50;
p->curX=p->startX-(rain_wind*5);
p->curY=p->startY+rain_len;
p->rainColor=random(15);
p->status=0;
p->flagR=random(10);
p->curR=random(3);
}
/*********创立整个链表**********/
void creatRain(void)
{
struct rainDrop *p1,*p2;/*定义两个指针*/
int i;
p1=p2=creatDrop();
head=p1; /*赋值头指针*/
for(i=0;i<rain_Num;i++) /*循环创立整个雨滴链表*/
{
p2=creatDrop();
p1->next=p2;
p1=p2;
}
}
/*********生成下一种雨滴 坐标位置**********/
void updateRainLineData(struct rainDrop *p)
{
if(big==2)/*加速为2个雨滴距离下落*/
{
p->startX=p->curX;
p->startY=p->curY;
p->curX=p->startX-(rain_wind*5);
p->curY=p->startY+rain_len;
p->startX=p->curX;
p->startY=p->curY;
p->curX=p->startX-(rain_wind*5);
p->curY=p->startY+rain_len;
p->startX=p->curX;
p->startY=p->curY;
}
if(big==1)/*加速为一种雨滴距离下落*/
{
p->startX=p->curX;
p->startY=p->curY;
p->curX=p->startX-(rain_wind*5);
p->curY=p->startY+rain_len;
p->startX=p->curX;
p->startY=p->curY;
}
else /*正常速度下落*/
{
p->startX=p->curX;
p->startY=p->curY;
}
p->curX=p->startX-(rain_wind*5);
p->curY=p->startY+rain_len;
}
/********雨雪选取函数***********/
selectWinter()
{
m=1;
}
selectSumm()
{
m=6;
}
/********分屏函数***********/
splitScreen(struct rainDrop *p)
{
curx=p->curX/200;
cury=p->curY/110;
switch(curx)
{
case 0:
switch(cury)
{
case 0:
case 1:selectSumm();break;
case 2:selectWinter();break;
case 3:selectSumm();break;
}break;
case 1:
switch(cury)
{
case 0:
case 1:selectWinter();break;
case 2:selectSumm();break;
case 3:selectWinter();break;
}break;
case 2:
switch(cury)
{
case 0:
case 1:selectSumm();break;
case 2:selectWinter();break;
case 3:selectSumm();break;
}break;
case 3:
switch(cury)
{
case 0:
case 1:selectWinter();break;
case 2:selectSumm();break;
case 3:selectWinter();break;
}break;
}
}
/********画出彩色雨滴***********/
void drawRainLine(struct rainDrop *p,int m)
{
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->curX,p->curY,0,360,5,4);
}
}
/********清除上一滴雨滴***********/
void clearRainLine(struct rainDrop *p,int m)
{
setcolor(BLACK);/*将雨滴赋予黑色*/
if (m>=3&&m<=11)
line(p->startX,p->startY,p->curX,p->curY);
else
{
setfillpattern(2,BLACK);
sector(p->curX,p->curY,0,360,5,4);
}
}
/********雨滴入数声音***********/
getsound()
{
int freq;
for(freq=300;freq<5000;freq+=50)
{
sound (freq);
delay(400);
}
nosound();
}
/*********雷电声音**********/
thunderesound()
{
int freq;
for(freq=1000;freq<;freq+=50)
{
sound (freq);
delay(5000);
}
nosound();
}
/*********下雨**********/
void rainDropDown(struct rainDrop *p,int m)
{
if(p->curY>=p->flag)
{
clearRainLine(p,m);
p->status=1;
getsound();
}
else
{
clearRainLine(p,m);
updateRainLineData(p);
drawRainLine(p,m);
}
}
/********雨圈生长变大***********/
void updateRainCircleData(struct rainDrop *p)
{
p->curR+=1;
}
/*********画出雨圈**********/
void drawRainCircle(struct rainDrop *p)
{
setcolor(p->rainColor);
ellipse(p->curX,p->curY,0,360,10+p->curR*3,p->curR);
}
/*******清理雨圈************/
void clearRainCircle(struct rainDrop *p)
{
setcolor(BLACK);
setfillpattern(2,BLUE);
sector(p->curX,p->curY,0,360,10+p->curR*3,p->curR);
}
/*******入水 水圈生成结束重新刷新雨点************/
void fallToWater(struct rainDrop *p)
{
if(p->curR>=p->flagR)
{
clearRainCircle(p);
recreatDrop(p);
}
else
{
clearRainCircle(p);
updateRainCircleData(p);
drawRainCircle(p);
}
}
/********画出雷电 ***********/
int drawthurder(struct rainDrop *p)
{
int i,j,k,x,y;
setbkcolor(BLACK);
p->thunderX1=random(300);
p->thunderY1=random(20);
setcolor(WHITE);
for(k=0;k<2;k++)
{
x=random(100);
y=random(100);
p->thunderX1+=x;
p->thunderY1+=y;
p->a=p->thunderX1;
p->b=p->thunderY1;
for(i=0;i<6;i++)
for(j=0;j<2;j++)
{
setfillpattern(0,WHITE);
p->thunderX2=p->thunderX1-thunder[i][j];
j++;
p->thunderY2=p->thunderY1+thunder[i][j];
line(p->thunderX1,p->thunderY1,p->thunderX2,p->thunderY2);
p->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);
}
}
/******* 函数实现释放链表收起画布 ***********/
void rainfree(void)
{
char mark;
struct rainDrop *p,*q;
p=head;
while(p!=NULL)
{
q=p;
p=p->next;
free(q);
}
closegraph();
}
/********键盘控制***********/
keyboardCon(struct rainDrop *p)
{
key=bioskey(0);
if(key==LEFT)
rain_wind+=1;
if(key==TWO)
{
m=1;
}
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,"Pond night rain fall color---thank you!");
outtextxy(500,400,"09060641 ");
}
/********河水***********/
river()
{
setfillpattern(0,BLUE);
bar(0,440,640,500);
}
/********下雨 ***********/
void rain(int m)
{
struct rainDrop *p;
p=head;
while(!(key==ESC))
{
keyboardCon(p);
while(!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);
drawthurder(p);
thunderesound();
}
key=NULL;
p=p->next;
}
}
}
/********软件开始简介***********/
void Introduction()
{
printf("******************************\n");
printf("******************************\n");
printf("Pond night rain fall color!\n");
printf("\tclass:09060641\n");
printf("******************************\n");
printf("******************************\n");
}
/*********过滤函数*************/
filter()
{
int i;
i=0;
while(i>=6)
{
if(rain_Num<0&&rain_Num>50)
{
printf("error\nNote Please enter less than fifty greater than zero\nrain_num:");
scanf("%d",&rain_Num);
}
else
i+=1;
if(rain_v<0&&rain_v>10)
{
printf("error\nNote Please enter less than fifty greater than zero\nrain_v:");
scanf("%d",&rain_v);
}
else
i+=1;
if(rain_len<0&&rain_len>50)
{
printf("error\nNote Please enter less than ten greater than zero\nrain_len:");
scanf("%d",&rain_len);
}
else
i+=1;
if(rain_wind<0&&rain_wind>10)
{
printf("error\nNote Please enter less than ten greater than zero\nrain_wind:");
scanf("%d",&rain_wind);
}
else
i+=1;
if(m<0&&m>10)
{
printf("error\nNote Please enter less than 12 greater than zero\nmonth:");
scanf("%d",&m);
}
else
i+=1;
}
}
/********全局变量输入及其鉴定***********/
void input()
{
printf("rain_num:\nNote Please enter less than fifty greater than zero");
scanf("%d",&rain_Num);
printf("rain_v:\nNote Please enter less than fifty greater than zero");
scanf("%d",&rain_v);
printf("rain_wind:\nNote Please enter less than ten greater than zero");
scanf("%d",&rain_wind);
printf("rain_length:\nNote Please enter less than fifty greater than zero");
scanf("%d",&rain_len);
printf("the month of the year:\nNote Please enter less than 12 greater than 1");
scanf("%d",&m);
filter();
big=1;
}
/********程序入口 主函数**********/
main()
{
Introduction();
input();
initgraphics();
creatRain();
river();
rain(m);
}
展开阅读全文