标题: [原创]turbo C++编写模仿下雨的程序??? [打印本页]

作者: res    时间: 2008-5-26 14:53
标题: [原创]turbo C++编写模仿下雨的程序???
请教大家一个问题 :谁知道用turbo C++编一个模仿下雨的程序,本人急需用,谢谢大家帮帮忙.
作者: a13758777532    时间: 2008-7-17 17:54
在纳哪用啊
作者: yangyi153    时间: 2008-9-10 10:29
唉我们貌似也要用

作者: iamcrr2006    时间: 2008-11-16 14:30
大哥  是下雪吧
作者: iamcrr2006    时间: 2008-11-16 14:33

#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>

#define POINT 200
#define DOWNSPEED 5
#define MOVESIZE 1
#define SHOW 1
#define HIDE 0

typedef struct
{
 int x;
 int y;
 int size;
}SNOW;

SNOW Snow[POINT];
int MaxX,MaxY;
int MaxSize=3;
int SnowColor=15;
int Delay=15000;
int CurSnow=0;
int *Map;

/********************************** Init_Graph *****************************/
void Init_Graph(){
 int gdriver=DETECT,gmode,errorcode;
 initgraph(&gdriver, &gmode, "G:\\turboc2\\");
 errorcode = graphresult();
 if (errorcode != grOk) /* an error occurred */
 {
  printf("Graphics error: %s\n", grapherrormsg(errorcode));
  printf("Press any key to halt:");
  getch();
  exit(1); /*terminate with an error code */
 }
 MaxX=getmaxx();
 MaxY=getmaxy();

 Map=(int *) malloc( sizeof(int)*MaxX );
}
/******************************** MakeSnow ********************************/
void MakeSnow()
{
 int i;
 if( CurSnow>=POINT ) return;
 for( i=0; Snow.size; i++ )
  ;
 CurSnow++;
 Snow.x=random(MaxX);
 Snow.y=random(DOWNSPEED);
 Snow.size=random(MaxSize)+1;
 
}
/******************************** Init_Data *******************************/
void Init_Data()
{
 int i;
 for( i=0; i< POINT; i++)
 {
  Snow.x=0;
  Snow.y=0;
  Snow.size=0;
 }
 for( i=0; i<MaxX; i++)
  Map=MaxY;
}
/********************************* Init **********************************/
void Init()
{
 Init_Graph();
 Init_Data();
 randomize();
 MakeSnow();
}
/******************************** GetKey ********************************/
void GetKey(int *ah,int *al){
 union REGS r;
 r.h.ah=0;
 int86(0x16,&r,&r);
 /*return r.h.al;*/
 *ah=r.h.ah;
 *al=r.h.al;
}
/********************************* SetSnow ******************************/
void ShowSnow( int x, int y, int size, int flag )
{
 int color=0;

 if ( flag ) color=15;
 switch( size )
 {
 case 1:
  putpixel( x, y, color );
  break;
 case 2:
  setcolor( color );
  line( x-1, y-1, x+1, y+1 );
  line( x-1, y+1, x+1, y-1 );
  break;
 case 3:
  setcolor( color );
  line( x-1, y-1, x+1, y+1 );
  line( x-1, y+1, x+1, y-1 );
  /*
  line( x-2, y-2, x+2, y+2 );
  line( x-2, y+2, x+2, y-2 );*/

  line( x-2, y, x+2, y );
  line( x, y-2, x, y+2 );
  break;
 }

}
/********************************* Check ********************************/
void Move( int n, int tox, int toy )
{
 int x, y, size, i, j;
 float person;

 x=Snow[n].x;
 y=Snow[n].y;
 size=Snow[n].size;
 /* check end */
 j=y;
 if( x<tox )
 {
  person=(DOWNSPEED *1.0) / ( tox-x )*1.0;
  for( i=x; i<=tox; i++ )
  {
   if( j>=Map )
   {
    tox=i-size;
    break;
   }
   j+=(int)( (i-x+1)*person );
  }
 }
 else if( x>tox )
 {
  person=(DOWNSPEED *1.0) / ( x-tox )*1.0;
  for( i=x; i>=tox; i-- )
  {
   if( j>=Map )
   {
    tox=i+size;
    break;
   }
   j+=(int)( (x-i+1)*person );
  }
 }
 
 if( y+DOWNSPEED>=Map[tox] )
 {
  switch( size )
  {
  case 1:
   Map[x]--;
   break;
  case 2:
   Map[x]-=2;
   if( x>0 && Map[x-1]>Map[x] ) Map[x-1]=Map[x];
   if( x<MaxX-1 && Map[x+1]>Map[x] ) Map[x+1]=Map[x];
   break;
  case 3:
   Map[x]-=3;
   if( x>1 && Map[x-2]>Map[x] ) Map[x-1]=Map[x];
   if( x>0 && Map[x-1]>Map[x] ) Map[x-1]=Map[x];

   if( x<MaxX-2 && Map[x+2]>Map[x] ) Map[x+1]=Map[x];
   if( x<MaxX-1 && Map[x+1]>Map[x] ) Map[x+1]=Map[x];
   break;
  }
  CurSnow--;
  y=Map[x]+size;
  Snow[n].x=x;
  Snow[n].y=y;
  Snow[n].size=0;
 }
 else /* not end */
 {
  Snow[n].x=tox;
  Snow[n].y=toy;
 }
}
/******************************** snow **********************************/
void Begin()
{
 int ah,al;
 int i,dir,

文章出处:http://www.diybl.com/course/3_program/c/c_js/2008224/100864.html






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1