| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 402 人关注过本帖
标题:Tanks有点问题:求助:!
只看楼主 加入收藏
Antwind
Rank: 2
等 级:论坛游民
帖 子:82
专家分:53
注 册:2010-7-11
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:7 
Tanks有点问题:求助:!
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define LEFT  0x4b00
#define RIGHT 0x4d00
#define UP    0x4800
#define DOWN  0x5000
#define ENTER   0x1c0d
#define ESC   0x011b
struct
  {
     struct   add
         {int x;
          int y;

          } a[10];
     enum
         {
         North,South,Weast,East
         }Dir;
  }tank[5];
struct
  {
       int x;
       int y;
       enum
          {
              north,south,weast,east
          }dir;

   } bullets[100]={0},Bull[100]={0};
int n=0,k=0;
int m;
void loadtanks(int ) ;
int left(int ) ;
int  right(int ) ;
int  up(int )     ;
int  down(int );
void shout(int );
void Shout();
void prin()  ;
void gameover();
void begin() ;
void main()
{
        int key;
        int i;
        int x;
        int token=1;
        begin();
        loadtanks(0);
        loadtanks(1);
        loadtanks(2);
        loadtanks(3);
        loadtanks(4);

        do{     delay(90000);
               prin();
               while(kbhit())
                        {
                               key=bioskey(0);
                               switch(key)
                                        {       case  ENTER :         Shout();break;
                                               case  ESC   :          token=0;break;

                                               case  LEFT  :           left(0);  break;
                                               case  RIGHT :           right(0); break;
                                               case  UP    :           up(0);    break;
                                               case  DOWN  :           down(0);  break;
                                          }
                                break;
                                       
                        }
               for(i=1;i<=4;i++)
                     {
                         x=i*rand();
                         x=abs(x);
                         x=x/32768.0*4;
                         x%=4;
                         switch(x)
                                        {
                                               case  0 :           left(i);  break;
                                               case  1 :           right(i); break;
                                               case  2    :           up(i);    break;
                                               case  3  :           down(i);  break;
                                          }
                      }

                x=rand();
                x=abs(x);
                x=x/32768.0*4;
                x%=4;
                x++;
                switch(x)
                                        {
                                              case   1:           shout(1);break;
                                              case   2:           shout(2);break;
                                              case   3:           shout(3);break;
                                              case   4:           shout(4);break;
                                        }
                                



             prin();

           }while(token);
           gameover();

}

void loadtanks(int m)
{    switch(m)
        {
            case   0:
                        tank[0].a[0].x=40;  tank[0].a[0].y=10;
                        tank[0].a[1].x=39;  tank[0].a[1].y=11;
                        tank[0].a[2].x=40;  tank[0].a[2].y=11;
                        tank[0].a[3].x=41;  tank[0].a[3].y=11;
                        tank[0].a[4].x=39;  tank[0].a[4].y=12;
                        tank[0].a[5].x=40;  tank[0].a[5].y=12;
                        tank[0].a[6].x=41;  tank[0].a[6].y=12;
                        tank[0].a[7].x=39;  tank[0].a[7].y=13;
                        tank[0].a[8].x=40;  tank[0].a[8].y=13;
                        tank[0].a[9].x=41;  tank[0].a[9].y=13;
                        break;
            case   1:
                        tank[1].a[0].x=4;   tank[1].a[0].y=4;
                        tank[1].a[1].x=1;   tank[1].a[1].y=3;
                        tank[1].a[2].x=2;   tank[1].a[2].y=3;
                        tank[1].a[3].x=3;   tank[1].a[3].y=3;
                        tank[1].a[4].x=1;   tank[1].a[4].y=4;
                        tank[1].a[5].x=2;   tank[1].a[5].y=4;
                        tank[1].a[6].x=3;   tank[1].a[6].y=4;
                        tank[1].a[7].x=1;   tank[1].a[7].y=5;
                        tank[1].a[8].x=2;   tank[1].a[8].y=5;
                        tank[1].a[9].x=3;   tank[1].a[9].y=5;
                        break;
             case   2:
                        tank[2].a[0].x=77;   tank[2].a[0].y=4;
                        tank[2].a[1].x=78;   tank[2].a[1].y=3;
                        tank[2].a[2].x=79;   tank[2].a[2].y=3;
                        tank[2].a[3].x=80;   tank[2].a[3].y=3;
                        tank[2].a[4].x=78;   tank[2].a[4].y=4;
                        tank[2].a[5].x=79;   tank[2].a[5].y=4;
                        tank[2].a[6].x=80;   tank[2].a[6].y=4;
                        tank[2].a[7].x=78;   tank[2].a[7].y=5;
                        tank[2].a[8].x=79;   tank[2].a[8].y=5;
                        tank[2].a[9].x=80;   tank[2].a[9].y=5;
                        break;

              case   3:
                        tank[3].a[0].x=4;   tank[3].a[0].y=24;
                        tank[3].a[1].x=1;   tank[3].a[1].y=23;
                        tank[3].a[2].x=2;   tank[3].a[2].y=23;
                        tank[3].a[3].x=3;   tank[3].a[3].y=23;
                        tank[3].a[4].x=1;   tank[3].a[4].y=24;
                        tank[3].a[5].x=2;   tank[3].a[5].y=24;
                        tank[3].a[6].x=3;   tank[3].a[6].y=24;
                        tank[3].a[7].x=1;   tank[3].a[7].y=25;
                        tank[3].a[8].x=2;   tank[3].a[8].y=25;
                        tank[3].a[9].x=3;   tank[3].a[9].y=25;
                        break;
             case   4:
                        tank[4].a[0].x=77;   tank[4].a[0].y=24;
                        tank[4].a[1].x=78;   tank[4].a[1].y=23;
                        tank[4].a[2].x=79;   tank[4].a[2].y=23;
                        tank[4].a[3].x=80;   tank[4].a[3].y=23;
                        tank[4].a[4].x=78;   tank[4].a[4].y=24;
                        tank[4].a[5].x=79;   tank[4].a[5].y=24;
                        tank[4].a[6].x=80;   tank[4].a[6].y=24;
                        tank[4].a[7].x=78;   tank[4].a[7].y=25;
                        tank[4].a[8].x=79;   tank[4].a[8].y=25;
                        tank[4].a[9].x=80;   tank[4].a[9].y=25;
                        break;

         }
}

int left(int m)
{
    int j=m+1;
    int i,p,q;
    tank[m].a[0].x=tank[m].a[4].x-1;
    tank[m].a[0].y=tank[m].a[4].y;
    tank[m].Dir=2;
    for(p=0;p<4;p++)
        {
           j%=5;
           for(i=1;i<=7;i+=3)
                {
                    for(q=0;q<10;q++)
                        {
                           if((tank[m].a[i].x-1==tank[j].a[q].x&&tank[m].a[i].y==tank[j].a[q].y)||tank[m].a[i].x-1<1)
                                     return ;
                         }
                 }
            j++;
         }
    for(i=0;i<=10;i++)
         {
            tank[m].a[i].x--;
          }



}

int right(int m)
{
    int j=m+1;
    int i,p,q;
    tank[m].a[0].x=tank[m].a[6].x+1;
    tank[m].a[0].y=tank[m].a[6].y;
    tank[m].Dir=3;
    for(p=0;p<4;p++)
        {
           j%=5;
           for(i=3;i<=9;i+=3)
                {
                    for(q=0;q<10;q++)
                        {
                           if((tank[m].a[i].x+1==tank[j].a[q].x&&tank[m].a[i].y==tank[j].a[q].y)||tank[m].a[i].x+1>80)
                                  return   ;
                         }
                 }
            j++;
         }
    for(i=0;i<=10;i++)
         {
            tank[m].a[i].x++;
          }


}

int up(int m)
{
    int j=m+1;
    int i,p,q;
    tank[m].a[0].x=tank[m].a[2].x;
    tank[m].a[0].y=tank[m].a[2].y-1;
    tank[m].Dir=0;
    for(p=0;p<4;p++)
        {
           j%=5;
           for(i=1;i<=3;i++)
                {
                    for(q=0;q<10;q++)
                        {
                           if((tank[m].a[i].x==tank[j].a[q].x&&tank[m].a[i].y-1==tank[j].a[q].y)||tank[m].a[i].y<3)
                               return  ;
                         }
                 }
            j++;
         }
    for(i=0;i<=10;i++)
         {
            tank[m].a[i].y--;
          }



}

int  down(int m)
{
    int j=m+1;
    int i,p,q;
    tank[m].a[0].x=tank[m].a[8].x;
    tank[m].a[0].y=tank[m].a[8].y+1;
    tank[m].Dir=1;
    for(p=0;p<4;p++)                   /*if the left have other tanks or the wall,not turn.*/
        {
           j%=5;
           for(i=7;i<=9;i++)
                {
                    for(q=0;q<10;q++)
                        {
                           if((tank[m].a[i].x==tank[j].a[q].x&&tank[m].a[i].y+1==tank[j].a[q].y)||tank[m].a[i].x>25)
                               return   ;
                         }
                 }
            j++;
         }
    for(i=0;i<=10;i++)              /*go left.     */
         {
            tank[m].a[i].y++;
          }



}

void shout(int m)    /*the enemies'bullets.*/
{
        bullets[k].x=tank[m].a[0].x;
        bullets[k].y=tank[m].a[0].y;
        bullets[k].dir=tank[m].Dir;
        k++;
}

void Shout()
{                    /*mine bullets.*/
        Bull[n].x=tank[0].a[0].x;
        Bull[n].y=tank[0].a[0].y;
        Bull[n].dir=tank[0].Dir;
        n++;
}



void prin()            /*this is print the tanksand the bullets. */
{
   int i,j,p,q;
  textmode(C80);
  window(0,0,80,25);
  clrscr();
  textbackground(BLUE);
  textcolor(GREEN);
  gotoxy(35,1);
  cprintf("Score:");
  for(i=1;i<=80;i++)
  {
       gotoxy(i,2);
       putch(4);

   }
   for(i=0;i<5;i++)          /*print the tanks.  */
   {
        for(j=0;j<10;j++)
             {
                gotoxy(tank[i].a[j].x,tank[i].a[j].y);
                putch(3);
              }
    }
    for(i=0;i<k;i++)           /*print the enemies'bullets.*/
    {
             if(bullets[i].x<1||bullets[i].x>80||bullets[i].y<3||bullets[i].y>25)
               continue;
             for(j=0;j<10;j++)
                {     if(bullets[i].x==tank[0].a[j].x&&bullets[i].y==tank[0].a[j].y)
                           gameover();

                 }

              switch(bullets[i].dir)
                        {
                                case  north:    bullets[i].y--; break;
                                case  south :   bullets[i].y++; break;
                                case  weast :   bullets[i].x--; break;
                                case  east  :   bullets[i].x++; break;
                         }
              gotoxy(bullets[i].x,bullets[i].y);
              putch(7);

    }
      for(i=0;i<n;i++)            /*print mine bullets.   */
    {
             if(Bull[i].x<1||Bull[i].x>80||Bull[i].y<3||Bull[i].y>25)
               continue;
             for(p=1;p<=4;p++)
             {
                for(j=0;j<10;j++)
                        {
                                 if(Bull[i].x==tank[p].a[j].x&&Bull[i].y==tank[p].a[j].y)
                                        {
                                                 loadtanks(p);
                                                 break;
                                        }

                        }
              }
              switch(Bull[i].dir)
                        {
                                case  north:    Bull[i].y--; break;
                                case  south :   Bull[i].y++; break;
                                case  weast :   Bull[i].x--; break;
                                case  east  :   Bull[i].x++; break;
                         }
              gotoxy(Bull[i].x,Bull[i].y);
              putch(7);


     }

}

void gameover()
{
        textmode(C80);
        window(0,0,80,25);
        clrscr();
        textbackground(BLUE);
        textcolor(GREEN);
        gotoxy(35,12);
        cprintf("Game Over");
        getch();
}

void begin()
{
        
        textmode(C80);
        window(0,0,80,25);

        textbackground(BLUE);
        textcolor(GREEN);
          clrscr();
        gotoxy(15,10);
        cprintf("Welcome to this game");
        gotoxy(15,11);
        cprintf("TANKS");
        gotoxy(15,13);
        cprintf("Are you Ready");
        gotoxy(15,14);
        cprintf("Let's Go!");
        gotoxy(15,19) ;
        cprintf("Press anykey to begin");
        getch();


}
搜索更多相关主题的帖子: Tanks 
2010-08-25 05:13
Antwind
Rank: 2
等 级:论坛游民
帖 子:82
专家分:53
注 册:2010-7-11
收藏
得分:0 
看哈啊;


/*************我就是程序;程序就是我!******************/
2010-08-25 05:14
jack10141
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:陕西西安
等 级:小飞侠
威 望:6
帖 子:706
专家分:2271
注 册:2010-8-10
收藏
得分:5 
回复 楼主 Antwind
把你的问题描述下了??

看了下,呵呵 TC下可以运行,但是效果,却不敢恭维

你的代码没有注释,看着很累呢。

我估计你过上几个月时间 自己也会看不懂自己的程序了!!

所以找问题,还是免了吧!!!

[ 本帖最后由 jack10141 于 2010-8-25 19:36 编辑 ]

Coding就像一盒巧克力,你永远不会知道你会遇到什么BUG
别跟我说你是不能的,这让我愤怒,因为这侮辱了你的智慧
2010-08-25 19:21
清风拂晓
Rank: 8Rank: 8
来 自:火星
等 级:蝙蝠侠
威 望:1
帖 子:356
专家分:889
注 册:2010-8-13
收藏
得分:5 
坦克游戏?

清风拂暮(木)
2010-08-25 20:05
御坂美琴
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:魔術の禁書目錄
等 级:小飞侠
威 望:9
帖 子:952
专家分:2929
注 册:2010-8-18
收藏
得分:5 
对不起,我的编译器无法编译通过你的程序,无法给你提供帮助
如果你需要的话,我可以帮你找网上的其它人写的程序给你参考
御坂回答

永远为正义而奋斗,锄强扶弱的Level 5 超能力者
とある魔術の禁書目錄インデックス__御み坂さか美み琴こと
http://bbs.bccn.net/space.php?action=threads&uid=483997
2010-08-25 22:46
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:5 
汗,连个注释也没有,很难改啊,你将注释填上,我来帮你改

欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-08-26 15:21
Antwind
Rank: 2
等 级:论坛游民
帖 子:82
专家分:53
注 册:2010-7-11
收藏
得分:0 
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define LEFT  0x4b00
#define RIGHT 0x4d00
#define UP    0x4800
#define DOWN  0x5000
#define ENTER   0x1c0d
#define ESC   0x011b
struct
  {
     struct   add
         {int x;
          int y;

          } a[10];
     enum
         {
         North,South,Weast,East
         }Dir;
  }tank[5]; /*5个坦克的坐标和炮筒的方向,自己的为0号,敌方的为1至4号*/
struct
  {
       int x;
       int y;
       enum
          {
              north,south,weast,east
          }dir;

   } bullets[100]={0},Bull[100]={0}; /*自己的子弹Bull和敌方的子弹bull,坐标和方向*/
int n=0,k=0;  /*n为自己的子弹个数,k为敌方的子弹个数*/
int m;
void loadtanks(int ) ;
int left(int ) ;
int  right(int ) ;
int  up(int )     ;
int  down(int );
void shout(int );
void Shout();
void prin()  ;
void gameover();
void begin() ;
void main()
{
        int key;
        int i;
        int x;
        int token=1;
        begin();
        loadtanks(0);  /*初始化坦克*/
        loadtanks(1);
        loadtanks(2);
        loadtanks(3);
        loadtanks(4);

        do{     delay(90000);
               prin();
               while(kbhit())    /*移动自己的坦克*/
                        {
                               key=bioskey(0);
                               switch(key)
                                        {       case  ENTER :         Shout();break;
                                               case  ESC   :          token=0;break;

                                               case  LEFT  :           left(0);  break;
                                               case  RIGHT :           right(0); break;
                                               case  UP    :           up(0);    break;
                                               case  DOWN  :           down(0);  break;
                                          }
                                break;
                                       
                        }
               for(i=1;i<=4;i++)                /*随机移动敌方的坦克*/
                     {
                         x=i*rand();
                         x=abs(x);
                         x=x/32768.0*4;
                         x%=4;
                         switch(x)
                                        {
                                               case  0 :           left(i);  break;
                                               case  1 :           right(i); break;
                                               case  2    :           up(i);    break;
                                               case  3  :           down(i);  break;
                                          }
                      }

                x=rand();
                x=abs(x);
                x=x/32768.0*4;
                x%=4;
                x++;
                switch(x)
                                        {
                                              case   1:           shout(1);break;
                                              case   2:           shout(2);break;
                                              case   3:           shout(3);break;
                                              case   4:           shout(4);break;
                                        }
                                



             prin();

           }while(token);
           gameover();

}

void loadtanks(int m)                   /*初始化坦克,分别为坐标*/
{    switch(m)
        {
            case   0:                   /*自己的坦克的坐标*/
                        tank[0].a[0].x=40;  tank[0].a[0].y=10;
                        tank[0].a[1].x=39;  tank[0].a[1].y=11;
                        tank[0].a[2].x=40;  tank[0].a[2].y=11;
                        tank[0].a[3].x=41;  tank[0].a[3].y=11;
                        tank[0].a[4].x=39;  tank[0].a[4].y=12;
                        tank[0].a[5].x=40;  tank[0].a[5].y=12;
                        tank[0].a[6].x=41;  tank[0].a[6].y=12;
                        tank[0].a[7].x=39;  tank[0].a[7].y=13;
                        tank[0].a[8].x=40;  tank[0].a[8].y=13;
                        tank[0].a[9].x=41;  tank[0].a[9].y=13;
                        break;           /*1至4为敌方的坦克坐标*/
            case   1:
                        tank[1].a[0].x=4;   tank[1].a[0].y=4;
                        tank[1].a[1].x=1;   tank[1].a[1].y=3;
                        tank[1].a[2].x=2;   tank[1].a[2].y=3;
                        tank[1].a[3].x=3;   tank[1].a[3].y=3;
                        tank[1].a[4].x=1;   tank[1].a[4].y=4;
                        tank[1].a[5].x=2;   tank[1].a[5].y=4;
                        tank[1].a[6].x=3;   tank[1].a[6].y=4;
                        tank[1].a[7].x=1;   tank[1].a[7].y=5;
                        tank[1].a[8].x=2;   tank[1].a[8].y=5;
                        tank[1].a[9].x=3;   tank[1].a[9].y=5;
                        break;
             case   2:
                        tank[2].a[0].x=77;   tank[2].a[0].y=4;
                        tank[2].a[1].x=78;   tank[2].a[1].y=3;
                        tank[2].a[2].x=79;   tank[2].a[2].y=3;
                        tank[2].a[3].x=80;   tank[2].a[3].y=3;
                        tank[2].a[4].x=78;   tank[2].a[4].y=4;
                        tank[2].a[5].x=79;   tank[2].a[5].y=4;
                        tank[2].a[6].x=80;   tank[2].a[6].y=4;
                        tank[2].a[7].x=78;   tank[2].a[7].y=5;
                        tank[2].a[8].x=79;   tank[2].a[8].y=5;
                        tank[2].a[9].x=80;   tank[2].a[9].y=5;
                        break;

              case   3:
                        tank[3].a[0].x=4;   tank[3].a[0].y=24;
                        tank[3].a[1].x=1;   tank[3].a[1].y=23;
                        tank[3].a[2].x=2;   tank[3].a[2].y=23;
                        tank[3].a[3].x=3;   tank[3].a[3].y=23;
                        tank[3].a[4].x=1;   tank[3].a[4].y=24;
                        tank[3].a[5].x=2;   tank[3].a[5].y=24;
                        tank[3].a[6].x=3;   tank[3].a[6].y=24;
                        tank[3].a[7].x=1;   tank[3].a[7].y=25;
                        tank[3].a[8].x=2;   tank[3].a[8].y=25;
                        tank[3].a[9].x=3;   tank[3].a[9].y=25;
                        break;
             case   4:
                        tank[4].a[0].x=77;   tank[4].a[0].y=24;
                        tank[4].a[1].x=78;   tank[4].a[1].y=23;
                        tank[4].a[2].x=79;   tank[4].a[2].y=23;
                        tank[4].a[3].x=80;   tank[4].a[3].y=23;
                        tank[4].a[4].x=78;   tank[4].a[4].y=24;
                        tank[4].a[5].x=79;   tank[4].a[5].y=24;
                        tank[4].a[6].x=80;   tank[4].a[6].y=24;
                        tank[4].a[7].x=78;   tank[4].a[7].y=25;
                        tank[4].a[8].x=79;   tank[4].a[8].y=25;
                        tank[4].a[9].x=80;   tank[4].a[9].y=25;
                        break;

         }
}

int left(int m)                /*操着坦克左转*/
{
    int j=m+1;
    int i,p,q;
    tank[m].a[0].x=tank[m].a[4].x-1;
    tank[m].a[0].y=tank[m].a[4].y;
    tank[m].Dir=2;
    for(p=0;p<4;p++)               /*遇到别的坦克和墙体不移动*/
        {
           j%=5;
           for(i=1;i<=7;i+=3)
                {
                    for(q=0;q<10;q++)
                        {
                           if((tank[m].a[i].x-1==tank[j].a[q].x&&tank[m].a[i].y==tank[j].a[q].y)||tank[m].a[i].x-1<1)
                                     return ;
                         }
                 }
            j++;
         }
    for(i=0;i<=10;i++)
         {
            tank[m].a[i].x--;
          }



}

int right(int m)                    /*同上*/
{
    int j=m+1;
    int i,p,q;
    tank[m].a[0].x=tank[m].a[6].x+1;
    tank[m].a[0].y=tank[m].a[6].y;
    tank[m].Dir=3;
    for(p=0;p<4;p++)
        {
           j%=5;
           for(i=3;i<=9;i+=3)
                {
                    for(q=0;q<10;q++)
                        {
                           if((tank[m].a[i].x+1==tank[j].a[q].x&&tank[m].a[i].y==tank[j].a[q].y)||tank[m].a[i].x+1>80)
                                  return   ;
                         }
                 }
            j++;
         }
    for(i=0;i<=10;i++)
         {
            tank[m].a[i].x++;
          }


}

int up(int m)
{
    int j=m+1;
    int i,p,q;
    tank[m].a[0].x=tank[m].a[2].x;
    tank[m].a[0].y=tank[m].a[2].y-1;
    tank[m].Dir=0;
    for(p=0;p<4;p++)
        {
           j%=5;
           for(i=1;i<=3;i++)
                {
                    for(q=0;q<10;q++)
                        {
                           if((tank[m].a[i].x==tank[j].a[q].x&&tank[m].a[i].y-1==tank[j].a[q].y)||tank[m].a[i].y<3)
                               return  ;
                         }
                 }
            j++;
         }
    for(i=0;i<=10;i++)
         {
            tank[m].a[i].y--;
          }



}

int  down(int m)
{
    int j=m+1;
    int i,p,q;
    tank[m].a[0].x=tank[m].a[8].x;
    tank[m].a[0].y=tank[m].a[8].y+1;
    tank[m].Dir=1;
    for(p=0;p<4;p++)                   /*if the left have other tanks or the wall,not turn.*/
        {
           j%=5;
           for(i=7;i<=9;i++)
                {
                    for(q=0;q<10;q++)
                        {
                           if((tank[m].a[i].x==tank[j].a[q].x&&tank[m].a[i].y+1==tank[j].a[q].y)||tank[m].a[i].x>25)
                               return   ;
                         }
                 }
            j++;
         }
    for(i=0;i<=10;i++)              /*go left.     */
         {
            tank[m].a[i].y++;
          }



}

void shout(int m)    /*the enemies'bullets.*/
{
        bullets[k].x=tank[m].a[0].x;
        bullets[k].y=tank[m].a[0].y;
        bullets[k].dir=tank[m].Dir;
        k++;
}

void Shout()
{                    /*mine bullets.*/
        Bull[n].x=tank[0].a[0].x;
        Bull[n].y=tank[0].a[0].y;
        Bull[n].dir=tank[0].Dir;
        n++;
}



void prin()            /*this is print the tanksand the bullets. */
{
   int i,j,p,q;
  textmode(C80);
  window(0,0,80,25);
  clrscr();
  textbackground(BLUE);
  textcolor(GREEN);
  gotoxy(35,1);
  cprintf("Score:");
  for(i=1;i<=80;i++)
  {
       gotoxy(i,2);
       putch(4);

   }
   for(i=0;i<5;i++)          /*print the tanks.  */
   {
        for(j=0;j<10;j++)
             {
                gotoxy(tank[i].a[j].x,tank[i].a[j].y);
                putch(3);
              }
    }
    for(i=0;i<k;i++)           /*print the enemies'bullets.*/
    {
             if(bullets[i].x<1||bullets[i].x>80||bullets[i].y<3||bullets[i].y>25)       /*超出屏幕不打印*/
               continue;
             for(j=0;j<10;j++)
                {     if(bullets[i].x==tank[0].a[j].x&&bullets[i].y==tank[0].a[j].y)     /*打到自己后游戏结束*/
                           gameover();

                 }

              switch(bullets[i].dir)
                        {
                                case  north:    bullets[i].y--; break;
                                case  south :   bullets[i].y++; break;
                                case  weast :   bullets[i].x--; break;
                                case  east  :   bullets[i].x++; break;
                         }
              gotoxy(bullets[i].x,bullets[i].y);
              putch(7);

    }
      for(i=0;i<n;i++)            /*print mine bullets.   */
    {
             if(Bull[i].x<1||Bull[i].x>80||Bull[i].y<3||Bull[i].y>25)   /*同上*/
               continue;
             for(p=1;p<=4;p++)
             {
                for(j=0;j<10;j++)
                        {
                                 if(Bull[i].x==tank[p].a[j].x&&Bull[i].y==tank[p].a[j].y)       /*打到敌方坦克后再初始化*/
                                        {
                                                 loadtanks(p);
                                                 break;
                                        }

                        }
              }
              switch(Bull[i].dir)
                        {
                                case  north:    Bull[i].y--; break;
                                case  south :   Bull[i].y++; break;
                                case  weast :   Bull[i].x--; break;
                                case  east  :   Bull[i].x++; break;
                         }
              gotoxy(Bull[i].x,Bull[i].y);
              putch(7);


     }

}

void gameover()                          /*游戏结束*/
{
        textmode(C80);
        window(0,0,80,25);
        clrscr();
        textbackground(BLUE);
        textcolor(GREEN);
        gotoxy(35,12);
        cprintf("Game Over");
        getch();
}

void begin()                 /*打印提示*/
{
        
        textmode(C80);
        window(0,0,80,25);

        textbackground(BLUE);
        textcolor(GREEN);
          clrscr();
        gotoxy(15,10);
        cprintf("Welcome to this game");
        gotoxy(15,11);
        cprintf("TANKS");
        gotoxy(15,13);
        cprintf("Are you Ready");
        gotoxy(15,14);
        cprintf("Let's Go!");
        gotoxy(15,19) ;
        cprintf("Press anykey to begin");
        getch();


}

麻烦大家再看哈:我写了一下注释。谢了


/*************我就是程序;程序就是我!******************/
2010-08-26 20:54
Antwind
Rank: 2
等 级:论坛游民
帖 子:82
专家分:53
注 册:2010-7-11
收藏
得分:0 
我用win-tc编的。
指点哈啊。


/*************我就是程序;程序就是我!******************/
2010-08-26 20:57
快速回复:Tanks有点问题:求助:!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024020 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved