当前位置: 代码迷 >> C语言 >> 急需帮助一个编程问题
  详细解决方案

急需帮助一个编程问题

热度:386   发布时间:2008-06-16 00:17:03.0
急需帮助一个编程问题
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#include <stdlib.h>
#include <dos.h>
#include <time.h>
#include <bios.h>
#define MAX 12
typedef struct
  {
     float x,y;
     float  vx,vy;
     int color;
  }ball;
void main()
  {
       int gd=DETECT,gm,i,j,k,t;
       ball ba[MAX];

       float dt=7e-2;
       int issuit(ball *,int i);
       void hitpro(ball*,int ,int);
        registerbgidriver(EGAVGA_driver);
          initgraph(&gd,&gm,"");
          srand(time(NULL));

          for(i=0;i<MAX;i++)
             {
                   ba[i].x=(rand()%5+1)*116;
                   ba[i].y=(rand()%3+1)*116;
                if (!issuit(ba,i)) {i--; continue;}
                ba[i].vx=rand()%50-25;
                ba[i].vy=rand()%50-25;
                ba[i].color=i+1;
             }
          ba[6].color=14;
          ba[7].color=13;

          while(!bioskey(1))
          {
                for(i=0;i<MAX;i++)
                      {
                           ba[i].x+=ba[i].vx*dt;
                           ba[i].y+=ba[i].vy*dt;
                      }
              for(j=0;j<MAX;j++)
                 {
                    for(k=j+1;k<MAX;k++)  hitpro(ba,j,k);
                     if (ba[j].x<51||ba[j].x>589) ba[j].vx=-ba[j].vx;
                    if (ba[j].y<51||ba[j].y>429) ba[j].vy=-ba[j].vy;
                 }
              cleardevice();
                   for(i=0;i<4*MAX;i++)
                      {
                          t=i%MAX;
                          setcolor(ba[t].color);
                          circle(ba[t].x,ba[t].y,50);
                              }
                  delay(2000);
             }
        closegraph();
  }
int issuit( ball *b1,int n)
  {
       int i,a,b,c,d;
          a=b1[n].x;
          b=b1[n].y;
          for(i=0;i<n;i++)
             {
                   c=b1[i].x;
                   d=b1[i].y;
                   if (a==c&&b==d) return 0;
             }
          return 1;
  }
void hitpro(ball *ba,int j ,int k )
  {
       float r,a,b,c,d,tx1,tx2,ty1,ty2,tem;
        tem=(ba[k].x-ba[j].x)*(ba[k].x-ba[j].x)+(ba[k].y-ba[j].y)*(ba[k].y-ba[j].y);
        r=sqrt(tem);
        if (r>102.0) return ;
       a=(ba[k].x-ba[j].x)/r;
       b=(ba[k].y-ba[j].y)/r;
       c=-b;
       d=a;
       r=sqrt(c*c+d*d);
       c/=r;
       d/=r;
       tx1=ba[j].vx*a+ba[j].vy*b;
       ty1=ba[j].vx*c+ba[j].vy*d;
       tx2=ba[k].vx*a+ba[k].vy*b;
          ty2=ba[k].vx*c+ba[k].vy*d;
       ba[j].vx=tx2*a+ty1*c;
       ba[j].vy=tx2*b+ty1*d;
       ba[k].vx=tx1*a+ty2*c;
       ba[k].vy=tx1*b+ty2*d;
  }
请问谁能翻译一下哦
搜索更多相关的解决方案: 编程  include  color  

----------------解决方案--------------------------------------------------------
楼主厉害厉害。。。。



[color=white]
----------------解决方案--------------------------------------------------------
你知道吗
----------------解决方案--------------------------------------------------------
  相关解决方案