Game.h
上传用户:kf1822
上传日期:2021-06-02
资源大小:2156k
文件大小:10k
源码类别:

游戏

开发平台:

Java

  1. #include <stdlib.h>
  2. #include "Back.h"
  3. #include "Human.h"
  4. #include "Word.h"
  5. #define VK_LEFT  0x4b00
  6. #define VK_RIGHT 0x4d00
  7. #define VK_SPACE 0x3920
  8. #define VK_ESC   0x011b
  9. void game()      /* 目前等同与Game函数 */
  10. {
  11.     int temp;
  12.     int i;
  13.     int tempY;     /* 用于标示两个板子之间的距离 */
  14.     int countBo;   /* 作用与判断板子是否能的修改的一个辅助标量 */
  15.     int key;
  16.     int count=0; /* 标记Human的颜色何时需要被修改 */
  17.     int countT=0;/* 标记Human的颜色何时需要被修改 */
  18.     int tempHu=0;  /* 用与标记该描绘1-Human 还是 0-Human1 */
  19.     int tempBo;    /* 用来标记弹板伸缩变化的标量 */
  20.     int isCarry;
  21.     int begin=0;     /* 爆炸 0-没开始 1-开始   */
  22.     int end=0;       /* 爆炸结束标记量 */
  23.     int gameStyle=0; /* 游戏界面转换标量 0-开始界面 1-游戏截面 2-游戏结束截面 */
  24.     int select=1;    /* 游戏开始界面选择star 和 exit 的标量 1-start  0-exit */
  25.     int color[2]={5,7};
  26.     int pr=0;   /* 层数标记 */
  27.     int speed=3; /* 全局速度变化量 */
  28.     int page=0;
  29.     int isChange=0;    /* 标示画面是否被改变了 */
  30.     Human h;
  31.     Board b[7];
  32.     Thorn t[34];
  33.     ExpStar st[20];
  34.     stars s[70];
  35.     randomize();
  36.     initThorn(t,34);
  37.     initStars(s,70);
  38.     while(1)
  39.     {
  40.         timeCounter++;
  41.         if(bioskey(1))
  42.             key=bioskey(0);
  43.         else
  44.             key=0;
  45.         switch(key)
  46.         {
  47.             case VK_LEFT:
  48.             if(gameStyle!=1)
  49.             {
  50.                 if(select==0)
  51.                     select=1;
  52.             }
  53.             if(gameStyle==1)
  54.             {
  55.                 count++;
  56.                 if(count%2==1)            /* 当按LEFT键的次数为双数时 颜色才需要改变一次     */
  57.                 {
  58.                     leftHuman(&h);
  59.                 }
  60.                 if(h.speed>0)
  61.                 {
  62.                     h.speed=-1*h.speed;
  63.                 }
  64.                 moveHuman(&h);
  65.                 if(h.x-7<=79)
  66.                 {
  67.                     h.x=86;
  68.                 }
  69.                 if(tempHu==1)
  70.                 {
  71.                     tempHu=0;
  72.                 }
  73.                 else                    /* 在此对Human的两个图象进行交替描绘 以模拟旋转状态 */
  74.                 {
  75.                     tempHu=1;
  76.                 }
  77.                 if(tempHu==0)
  78.                     countT=0;
  79.                 else
  80.                     countT=1;
  81.             }
  82.             break;
  83.             case VK_RIGHT:
  84.             if(gameStyle!=1)
  85.             {
  86.                 if(select==1)
  87.                     select=0;
  88.             }
  89.             if(gameStyle==1)
  90.             {
  91.                 countT++;                 /* 当按RIGHT键的次数为单数时 颜色才需要被改变一次   */
  92.                 if(countT%2==0)
  93.                 {
  94.                     rightHuman(&h);
  95.                 }
  96.                 if(h.speed<0)
  97.                 {
  98.                     h.speed=-1*h.speed;
  99.                 }
  100.                 moveHuman(&h);
  101.                 if(h.x+7>=418)
  102.                 {
  103.                     h.x=411;
  104.                 }
  105.                 if(tempHu==1)
  106.                 {
  107.                     tempHu=0;
  108.                 }
  109.                 else                    /* 在此对Human的两个图象进行交替描绘 以模拟旋转状态 */
  110.                 {
  111.                     tempHu=1;
  112.                 }
  113.                 if(tempHu==1)
  114.                     count=1;
  115.                 else
  116.                     count=0;
  117.             }
  118.             break;
  119.             case VK_SPACE:
  120.                 if(gameStyle!=1)
  121.                 {
  122.                     if(select==1)
  123.                     {
  124.                         isChange=1;
  125.                         setfillstyle(1,BLACK);
  126.                         bar(0,0,639,349);
  127.                         initAllBoard(b,7,0);
  128.                         drawDoor();
  129.                         b[0].isChange=1;     /* 初始状态下先让第一个板子可以上升 */
  130.                         b[0].y=340;         /* 让第一块板子从340这个Y坐标开始 因为考虑到Human在开始时在第一块板上出现 */
  131.                         b[0].temp=0;         /* 让第一块板子为普通板 */
  132.                         initHuman(&h,b[0]);
  133.                         h.isCarry=1;
  134.                         gameStyle=1; /* 进入游戏界面 */
  135.                         h.life=10;
  136.                         pr=0;
  137.                         speed=3;
  138.                     }
  139.                     else
  140.                         return;
  141.                 }
  142.             break;
  143.             case VK_ESC:
  144.             return;
  145.         }
  146.         setactivepage(page);
  147.         if(isChange==1)
  148.         {
  149.             setfillstyle(1,BLACK);
  150.             bar(0,0,639,349);
  151.             isChange=2;
  152.         }
  153.         if(gameStyle!=1)
  154.         {
  155.             if(gameStyle==0)
  156.             {
  157.                 drawMainBoard();
  158.                 beginBack(color,2);
  159.             }
  160.             if(gameStyle==2)
  161.             {
  162.                 if(isChange==2)
  163.                 {
  164.                     setfillstyle(1,BLACK);
  165.                     bar(0,0,639,349);
  166.                     isChange=0;
  167.                  }
  168.                 endBoard();
  169.             }
  170.             if(select==1)
  171.             {
  172.                 setfillstyle(1,BLACK);
  173.                 bar(407,231,444,236);
  174.                 setfillstyle(1,GREEN);
  175.                 bar(175,231,212,236);
  176.             }
  177.             else
  178.             {
  179.                 setfillstyle(1,BLACK);
  180.                 bar(175,231,212,236);
  181.                 setfillstyle(1,GREEN);
  182.                 bar(407,231,444,236);
  183.             }
  184.             setcolor(RED);
  185.             rectangle(175,231,212,236);
  186.             setcolor(RED);
  187.             rectangle(407,231,444,236);;
  188.         }
  189.         if(gameStyle==1)
  190.         {
  191.             setfillstyle(1,BLACK);
  192.             bar(79,0,418,349);
  193.             drawThorn(t,34);
  194.             drawAllStars(s,70);
  195.             drawPrBoard(pr);    /* 记层数牌 */
  196.             drawLife(h.life);    /* 记生命牌 */
  197.             if(begin==1)
  198.             {
  199.                 drawExpEdBoard(st,20);
  200.                 for(i=0;i<20;i++)
  201.                 {
  202.                     if(st[i].isShow==0)
  203.                         end++;
  204.                     if(end==20)      /* 当所有的爆炸星星都消失后 爆炸结束 */
  205.                     {
  206.                         begin=0;
  207.                         end=0;
  208.                     }
  209.                 }
  210.             }
  211.             for(i=0;i<7;i++)
  212.             {
  213.                 drawBoards(b[i]);
  214.             }
  215.             if(tempHu==1)             /* 当无按键状态时 保持Human最后状态 无须交替状态 */
  216.                 drawHuman1(h);
  217.             else
  218.                 drawHuman(h);
  219.         }
  220.         if(timeCounter>speed)   /* 速度会改变的用这个时间中断 */
  221.         {
  222.             timeCounter=0;
  223.             if(gameStyle==0)
  224.             {
  225.                 changeColor(color,2);
  226.             }
  227.             if(gameStyle==1)
  228.             {
  229.                 tempY=rand()%40+40;  /* 标示板与板之间的距离为随即的14--24 (考虑到板子厚度) */
  230.                 for(i=0;i<7;i++)
  231.                 {
  232.                     if(b[i].temp==5)
  233.                     {
  234.                         b[i].temp=2;
  235.                     }
  236.                 }
  237.                 for(i=0;i<70;i++)          /* 移动星星 */
  238.                 {
  239.                     if(s[i].py>=353)
  240.                         s[i].py=0;
  241.                     s[i].py++;
  242.                 }
  243.                 for(i=0;i<7;i++)
  244.                 {
  245.                     if(b[i].isChange==1)
  246.                     {
  247.                         b[i].y=b[i].y-b[i].speed;    /* 板子的移动Y坐标变化量 */
  248.                         b[i].tempL--;           /* 滑板传送带向左移动的速度变化和范围 */
  249.                         if(b[i].tempL<0)
  250.                             b[i].tempL=6;
  251.                         b[i].tempR++;           /* 滑板传送带向右移动的速度变化和范围 */
  252.                         if(b[i].tempR>=7)
  253.                             b[i].tempR=0;
  254.                     }
  255.                     if(i==6)               /* 判断第一块板子在最后一块板子下面的情况 */
  256.                     {
  257.                         countBo=0;
  258.                     }
  259.                     else
  260.                     {
  261.                         countBo=i+1;
  262.                     }
  263.                     if(b[countBo].y-b[i].y>=tempY)  /* 判断前一个板子与后一个板子的距离是否在限定范围内 */
  264.                     {
  265.                         b[countBo].isChange=1;
  266.                     }
  267.                 }
  268.                 for(i=0;i<7;i++)
  269.                 {
  270.                     if(b[i].y<=62)   /* 46为游戏界面刺的起始Y坐标 */
  271.                     {
  272.                         pr++;
  273.                         if(pr%5==0)  /* 5块板子为一个速度等级的跳跃 */
  274.                         {
  275.                             if(speed>0)    /* 实际速度等级只有3个级别 当speed为0时最高 */
  276.                                 speed--;
  277.                         }
  278.                         chooseBoard(b,i+1,i);   /* 如果发现有板子移动超过上述范围 */
  279.                         initAllBoard(b,i+1,i);  /* 就重新选择板子类型并且给该板子重新赋初始值 */
  280.                     }
  281.                 }
  282.                 carryHuman(&h,b,7);
  283.                 h.y=h.y+h.vy;
  284.                 h.x=h.x+h.vx;
  285.                 if(h.y<=68)   /* 加上半径小于刺的下端 */
  286.                 {
  287.                     h.vy=5;
  288.                     h.isCarry=0;
  289.                     h.life=h.life-3;
  290.                 }
  291.                 if(h.y>=349 || h.life<1)      /* 判断游戏结束 */
  292.                 {
  293.                     setfillstyle(1,BLACK);
  294.                     bar(0,0,639,349);
  295.                     gameStyle=2;              /* 当游戏结束了以后 进入游戏结束画面 */
  296.                 }
  297.                 if(h.time==7)     /* 记时10次 爆炸引发*/
  298.                 {
  299.                     b[h.isCarry-1].isShow=0;        /* 爆炸开始 无爆炸状态下的爆炸板子就不用描绘了 */
  300.                     h.time=0;                       /* 记时还原 */
  301.                     initExpEdBoard(b[h.isCarry-1],st,20);
  302.                     h.isCarry=0;                    /* Human变为无承载状态 开始下落 */
  303.                     begin=1;
  304.                 }
  305.                 if(begin==1)
  306.                 {
  307.                     moveExpEdBoard(st,20);
  308.                 }
  309.             }
  310.         }
  311.         page=(page+1)%2;
  312.         setvisualpage(page);
  313.     }
  314.     /*killTimer();*/
  315. }