找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 8777|回复: 4
打印 上一主题 下一主题
收起左侧

[原创]turbo C++编写模仿下雨的程序???

[复制链接]
跳转到指定楼层
楼主
ID:2356 发表于 2008-5-26 14:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请教大家一个问题 :谁知道用turbo C++编一个模仿下雨的程序,本人急需用,谢谢大家帮帮忙.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:3271 发表于 2008-7-17 17:54 | 只看该作者
在纳哪用啊
回复

使用道具 举报

板凳
ID:5141 发表于 2008-9-10 10:29 | 只看该作者
唉我们貌似也要用
回复

使用道具 举报

地板
ID:5069 发表于 2008-11-16 14:30 | 只看该作者
大哥  是下雪吧
回复

使用道具 举报

5#
ID:5069 发表于 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

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表