C++控制台打飞机小游戏_c++控制10秒后boss出现-程序员宅基地

技术标签: 程序人生  

视频在这:https://v.youku.com/v_show/id_XNDQxMTQwNDA3Mg==.html

具体信息主界面上都有写。

按空格暂停,建议暂停后再升级属性。

记录最高分的文件进行了加密。

有boss(上面视频2分47秒)。

挺好玩的。

可能有bug,不想改了,整体体验不错就行了。

更多控制台操作可以看之前写的鼠标操作的文章(https://blog.csdn.net/C20190102/article/details/79301667),也可以直接在这个上面复制。

MinGW编译无错误,只有lld输出的几个警告。

只有一个文件,没有任何其他的东西。

可以直接扒下来编译。

一开始写的时候打了很多注释,后来就不想打了。

大家凑合着看吧,不清楚的就评论,如果我还记得到就答一下哈。

对了,为了防止暂停作弊,暂停过后开始时鼠标会回到飞机的位置。

这个代码我一个人可能总共肝了20多个小时,如果你能帮我改得更有趣,bug更少的话可以找我。

更多内容看代码:

  1. #include<set>

  2. #include<cmath>

  3. #include<ctime>

  4. #include<cstdio>

  5. #include<cstdlib>

  6. #include<vector>

  7. #include<windows.h>

  8. #include<algorithm>

  9. #include<iostream>

  10. #include<conio.h>

  11. #include<fstream>

  12. using namespace std;

  13.  
  14. #define fblack 0

  15. #define fblue 1

  16. #define fgreen 2

  17. #define fcyan 3

  18. #define fred 4

  19. #define fpurple 5

  20. #define fyellow 6

  21. #define fwhite 7

  22. #define fgray 8

  23. #define flight 8

  24. #define bblack 0

  25. #define bblue 16

  26. #define bgreen 32

  27. #define bcyan 48

  28. #define bfred 64

  29. #define bpurple 80

  30. #define byellow 96

  31. #define bwhite 112

  32. #define bgray 128

  33. #define blight 128

  34. #define dirkey -32

  35. #define upkey 72

  36. #define downkey 80

  37. #define leftkey 75

  38. #define rightkey 77

  39. #define wclear system("cls")

  40. #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)

  41. #define LL long long

  42.  
  43. void flash(int times){

  44.     while(times--){

  45.         system("color 08");

  46.         Sleep(300);

  47.         system("color 80");

  48.         Sleep(300);

  49.     }

  50.     //Sleep(1000);

  51.     system("color 08");

  52. }

  53. void HindCursor(){

  54.     HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);

  55.     CONSOLE_CURSOR_INFO CursorInfo;

  56.     GetConsoleCursorInfo(handle,&CursorInfo);

  57.     CursorInfo.bVisible=false;

  58.     SetConsoleCursorInfo(handle,&CursorInfo);

  59. }

  60. struct Button{

  61.     int x,y,color;

  62.     const char *name;

  63.     int len;

  64. };

  65. void GetPos(POINT &pt){

  66.     HWND hwnd=GetForegroundWindow();

  67.     GetCursorPos(&pt);

  68.     ScreenToClient(hwnd,&pt);

  69.     pt.y=pt.y/16,pt.x=pt.x/8;

  70.     swap(pt.x,pt.y);

  71. }

  72. void color(int a){

  73.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);

  74. }

  75. void gto(int x,int y){

  76.     COORD pos;pos.X=y;pos.Y=x;

  77.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);

  78. }

  79. Button NewButton(int x,int y,int color,const char *name){

  80.     Button t;

  81.     t.x=x,t.y=y,t.name=name;

  82.     t.color=color;

  83.     t.len=strlen(name);

  84.     return t;

  85. }

  86. bool Preserve(Button A){

  87.     gto(A.x,A.y),color(A.color),printf("%s",A.name);

  88.     POINT pt;

  89.     GetPos(pt);

  90.     if(pt.x==A.x&&(pt.y>=A.y&&pt.y<=A.y+A.len)){

  91.         color(112),gto(A.x,A.y),printf("%s",A.name);

  92.         if(KEY_DOWN(MOUSE_MOVED)) return 1;

  93.     }

  94.     return 0;

  95. }

  96. pair<int,int> GetXY(){

  97.     HANDLE hStdout;

  98.     CONSOLE_SCREEN_BUFFER_INFO pBuffer;

  99.     hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

  100.     GetConsoleScreenBufferInfo(hStdout, &pBuffer);

  101.     return make_pair(pBuffer.dwCursorPosition.Y,pBuffer.dwCursorPosition.X);

  102. }

  103. template <typename T>void Tprint(int Nx,int Ny,int Color,T a){

  104.     int x=GetXY().first,y=GetXY().second;

  105.     gto(Nx,Ny),color(Color),cout<<a;

  106.     gto(x,y);

  107. }

  108. void ColorPrint(){

  109.     for(int i=0;i<256;i++)

  110.         color(i),printf("%d\n",i);

  111. }

  112. void SetWindow(const char *name,int c,int w){

  113.     char str[30];

  114.     sprintf(str,"title %s",name);

  115.     system(str);

  116.     sprintf(str,"mode con cols=%d lines=%d",w,c);

  117.     system(str);

  118. }

  119. void SetWindow(const char *name,int c,int w,int x,int y){

  120.     SetConsoleTitle(name);

  121.     HWND hwnd;

  122.     hwnd=GetForegroundWindow();

  123.     SetWindowPos(hwnd,HWND_TOP,y,x,w*8,c*16,SWP_SHOWWINDOW);

  124. }

  125. int read(){

  126.     color(fwhite+flight);

  127.     int x=0,f=1;char c=getchar();

  128.     while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}

  129.     while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}

  130.     return x*f;

  131. }

  132.  
  133. #define TP Tprint

  134. #define WINDOWC 45

  135. #define WINDOWW 55

  136. #define INF 0x3f3f3f3f

  137. #define OC fwhite+flight+bblack //original color

  138.  
  139. bool InRange(int x){

  140.     return x>=0&&x<=WINDOWC;

  141. }

  142.  
  143. int BossFlag;

  144. int OwnShotTimes,OwnLoseBlood,OwnShotOnTimes;

  145. int MoneyFlash,ScoreFlash;

  146.  
  147. const int ConstNewDy[4]={-1,0,1};

  148. #define MAX_BULLET_TYPE_NUM 3

  149. const int ConstBulletColor[MAX_BULLET_TYPE_NUM+5]={0,fyellow,fred+flight,fred+flight,fblue+flight,fred+bwhite};

  150. const char ConstBulletShape[MAX_BULLET_TYPE_NUM+5]={0,'*','*','O','|','%'};

  151. const int ConstBulletDamage[MAX_BULLET_TYPE_NUM+5]={0,50,80,500,20,300};

  152. /*Move 1 block every 100-Speed ms*/

  153. const int ConstBulletSpeed[MAX_BULLET_TYPE_NUM+5]={0,50,30,10,80,20};

  154. /*The color of the full block in the blood line*/

  155. const int ConstBloodColor[4]={0,fred,fyellow,fgreen};

  156.  
  157. #define MAX_BOSS_NUM 10

  158. const int ConstBossFullBlood[MAX_BOSS_NUM+5]={0,1000,3000,5000,10000,30000,50000,100000,300000,500000,1000000};

  159. const int ConstBossShotSpeed[MAX_BOSS_NUM+5][2]={ {0,0},{30,-3900},{30,-3400},{50,-2900},{50,-2400},{70,-1900},{70,-1400},{90,-900},{90,-400},{100,-400},{100,-400}};

  160. const int ConstBossStopCD[MAX_BOSS_NUM+5]={0,3200,3400,3600,3800,4000,4200,4400,4600,4800,5000};

  161. const int ConstBossStopTime[MAX_BOSS_NUM+5]={0,3000,2800,2600,2400,2200,2000,1800,1600,1400,1200};

  162. const int ConstBossMoveSpeed[MAX_BOSS_NUM+5]={0,800,800,800,850,850,850,900,900,900,950};

  163. const int ConstBossScore[MAX_BOSS_NUM+5]={0,10000,20000,40000,80000,160000,320000,640000,1280000,2560000,5120000};

  164. const int ConstBossMoney[MAX_BOSS_NUM+5]={0,100,200,500,1000,2000,5000,8000,10000,20000,50000};

  165. const int ConstBossNeedScore[MAX_BOSS_NUM+5]={0,500,1000,1500,2000,2500,3000,3500,4000,4500,5000};

  166.  
  167. struct Bullet{

  168.     int isExist;

  169.     int x,y,Type;

  170.     int dx,dy,LastBulletRefreshTime;

  171.     Bullet(){LastBulletRefreshTime=-INF;}

  172.     Bullet(int isExist_,int x_,int y_,int Type_,int dx_,int dy_):

  173.         isExist(isExist_),x(x_),y(y_),Type(Type_),dx(dx_),dy(dy_){}

  174. };

  175.  
  176. void MoveBullet(Bullet&);

  177. /*We must use Bullet*, or we can't change the data(position of the bullet) in the set*/

  178. set<Bullet*> Ammo;

  179. void BulletsRefresh(){

  180.     vector<set<Bullet*>::iterator> Throw;

  181.     for(set<Bullet*>::iterator it=Ammo.begin();it!=Ammo.end();it++){

  182.         Bullet *New=*it;

  183.         MoveBullet(*New);

  184.         /*We can't erase it right away*/

  185.         if(!New->isExist)

  186.             Throw.push_back(it);

  187.     }

  188.     for(int i=0;i<int(Throw.size());i++)

  189.         Ammo.erase(Throw[i]);

  190. }

  191.  
  192. int BEGINTIME;

  193.  
  194. int UFOAddBlood,UFOAddShotSpeed,UFOAddMoveSpeed,Added;

  195.  
  196. struct UFO{

  197.     /*

  198.     Shape of the UFO:

  199.     0000/0000

  200.        @@@

  201.       (OOO)

  202.        \-/

  203.         V

  204.     */

  205.     int isExist;

  206.     int x,y;//position of the head

  207.     int dx,dy;

  208.     int Blood,FullBlood;

  209.     int ShotSpeed,LastShotTime;

  210.     int MoveSpeed;

  211.     int LastMoveTime;

  212.     int Score,Money;

  213.  
  214.     UFO(){

  215.         if(BossFlag&&!Added)

  216.             UFOAddBlood+=100,UFOAddShotSpeed+=100,UFOAddMoveSpeed+=100,Added=1;

  217.         if(!BossFlag&&Added)

  218.             UFOAddBlood-=100,UFOAddShotSpeed-=100,UFOAddMoveSpeed-=100,Added=0;

  219.         isExist=1;

  220.         x=0,y=rand()%(WINDOWW-4)+4;//Must be in the screen

  221.         FullBlood=rand()%300+100+UFOAddBlood;

  222.         Blood=FullBlood;

  223.         ShotSpeed=rand()%1000+UFOAddShotSpeed;

  224.         /*Move 1 block every 1000-MoveSpeed ms*/

  225.         MoveSpeed=rand()%600+300+UFOAddMoveSpeed;

  226.         LastMoveTime=LastShotTime=-INF;

  227.         dx=1,dy=0;

  228.         Score=FullBlood/30+((clock()-BEGINTIME)/10000);

  229.         Money=MoveSpeed/100.0+FullBlood/100.0;

  230.     }

  231.     /*effects when being hit*/

  232.     void Flash(){

  233.         /*the head is sure to be in the screen so we needn't check*/

  234.         if(!isExist)

  235.             return;

  236.         if(x>0&&x<WINDOWC)

  237.             TP(x,y,fpurple+bwhite,'V');

  238.         if(x-1>0&&x-1<WINDOWC)

  239.             TP(x-1,y-1,fpurple+bwhite,"\\-/");

  240.         //Sleep(100);

  241.         if(x>0&&x<WINDOWC)

  242.             TP(x,y,fpurple+bblack,'V');

  243.         if(x-1>0&&x-1<WINDOWC)

  244.             TP(x-1,y-1,fpurple+bblack,"\\-/");

  245.     }

  246.     /*Check if hit only on the body*/

  247.     bool Hit(int tx,int ty){

  248.         return (tx==x&&ty==y)||

  249.                (tx==x-1&&ty>=y-1&&ty<=y+1);

  250.     }

  251.     /*To check if it will hit another UFO*/

  252.     void BloodRefresh(int NewX,int NewY){

  253.         /*To appear gradually, we should check the position*/

  254.         if(x-2>=0){

  255.             TP(x-2,y-1,OC,"   ");

  256.             if(isExist)

  257.                 if(NewX-2<WINDOWC){

  258.                     /*Round up*/

  259.                     int FullBlock=(Blood*3+FullBlood-1)/FullBlood;   //Number of "@"

  260.                     int EmptyBlock=3-FullBlock;                      //Number of "O"

  261.                     int BloodColor=ConstBloodColor[FullBlock];

  262.                     /*Print the blood line*/

  263.                     for(int i=1;i<=FullBlock;i++)

  264.                         TP(NewX-2,NewY-2+i,BloodColor+bblack,'@');

  265.                     for(int i=1;i<=EmptyBlock;i++)

  266.                         TP(NewX-2,NewY-2+FullBlock+i,fgray+bblack,'O');

  267.                 }

  268.         }

  269.         /*Print the blood/fullblood number*/

  270.         /*Due to %06d we can't use TP*/

  271.         if(x-3>=0){

  272.             TP(x-3,y-4,OC,"         ");

  273.             if(isExist){

  274.                 if(NewX-3<WINDOWC){

  275.                     gto(NewX-3,NewY-4),color(fcyan+bblack),printf("%04d",Blood);

  276.                     TP(NewX-3,NewY,fcyan+bblack,'/');

  277.                     gto(NewX-3,NewY+1),color(fcyan+bblack),printf("%04d",FullBlood);

  278.                 }

  279.             }

  280.         }

  281.         if(x-3>=WINDOWC)

  282.             isExist=0;

  283.     }

  284.     /*Clear the shape after it died*/

  285.     void ClearPrint(){

  286.         BloodRefresh(x,y);

  287.         if(x-1>=0&&x-1<WINDOWC)

  288.             TP(x-1,y-1,OC,"   ");

  289.         if(x>=0&&x<WINDOWC)

  290.             TP(x,y,OC,' ');

  291.     }

  292.     void Shot(){

  293.         int t=clock();

  294.         if(!ShotSpeed||LastShotTime>=t-(5000-ShotSpeed))

  295.             return;

  296.         LastShotTime=t;

  297.         if(x>0){

  298.             Bullet *tmp=new Bullet(1,x+1,y,2,1,0);

  299.             Ammo.insert(tmp);

  300.         }

  301.     }

  302. };

  303. /*It is similar to set<Bullet*> in struct Plane*/

  304. set<UFO*> Enemy;

  305.  
  306. bool UFOCrash(int,int);

  307. bool UFOCrash(UFO,int,int,set<UFO*>::iterator);

  308.  
  309. /*Move the plane to a new place*/

  310. void UFOMovePrint(UFO &me,set<UFO*>::iterator id){

  311.     int t=clock();

  312.     if(me.LastMoveTime>=t-(1000-me.MoveSpeed))

  313.         return;

  314.     me.LastMoveTime=t;

  315.     /*Change the direction*/

  316.     if(rand()%3==0)

  317.         me.dy=ConstNewDy[rand()%3];

  318.     int NewX=me.x+me.dx,NewY=me.y+me.dy;

  319.     if(UFOCrash(me,NewX,NewY,id)||NewY-4<0||NewY+4>=WINDOWW)//||NewX<0||NewY-4<0||NewX>=WINDOWC||NewY+4>=WINDOWW){

  320.         for(int i=0;i<3;i++){

  321.             me.dy=ConstNewDy[rand()%3];

  322.             NewX=me.x+me.dx,NewY=me.y+me.dy;

  323.             if(!(UFOCrash(me,NewX,NewY,id)||NewY-4<0||NewY+4>=WINDOWW))//||NewX<0||NewY-4<0||NewX>=WINDOWC||NewY+4>=WINDOWW))

  324.                 break;

  325.         }

  326.  
  327.     if(UFOCrash(me,NewX,NewY,id)||NewY-4<0||NewY+4>=WINDOWW)//||NewX<0||NewY-4<0||NewX>=WINDOWC||NewY+4>=WINDOWW)

  328.         return;

  329.     //TP(me.x,me.y,OC,' ');

  330.     if(NewX<WINDOWC){

  331.         TP(me.x,me.y,fwhite+flight+bblack,' ');

  332.         if(me.isExist) TP(NewX,NewY,fwhite+flight+bblack,'V');

  333.     }

  334.     if(NewX-1>=0&&NewX-1<WINDOWC){

  335.         TP(me.x-1,me.y-1,fwhite+flight+bblack,"   ");

  336.         if(me.isExist) TP(NewX-1,NewY-1,fwhite+flight+bblack,"\\-/");

  337.     }

  338.     me.BloodRefresh(NewX,NewY);

  339.     me.x=NewX,me.y=NewY;

  340. }

  341. int UFORefreshTime=3000,LastUFORefreshTime=0;

  342. void UFORefresh(){

  343.     int t=clock();

  344.     if(LastUFORefreshTime<t-UFORefreshTime){

  345.         UFO *tmp=new UFO;

  346.         Enemy.insert(tmp);

  347.         LastUFORefreshTime=t;

  348.     }

  349.     vector<set<UFO*>::iterator> Throw;

  350.     for(set<UFO*>::iterator it=Enemy.begin();it!=Enemy.end();it++){

  351.         UFO *New=*it;

  352.         if(!New->isExist)

  353.             Throw.push_back(it);

  354.         UFOMovePrint(*New,it);

  355.         New->Shot();

  356.     }

  357.     for(int i=0;i<int(Throw.size());i++)

  358.         Enemy.erase(Throw[i]);

  359. }

  360.  
  361. #define MAX_BUFF_NUM 5

  362. const int ConstBuffAppearPossibility[2][1000]={

  363.     {1,2,2,2,2,2,2,3,4,5},

  364.     {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,5}

  365. };

  366. const int ConstBuffAppearTime[MAX_BUFF_NUM+5]={0,5000,5000,5000,5000,5000};

  367. const int ConstBuffLastTime[MAX_BUFF_NUM+5]={0,5000,0,5000,10000,5000};

  368. const char ConstBuffName[MAX_BUFF_NUM+5]={0,'B','C','P','D','S'};

  369. const char ConstBuffColor[MAX_BUFF_NUM+5]={0,fblue+flight,fgreen+flight,fred+flight,fyellow+flight,fpurple+flight};

  370.  
  371. struct Plane{

  372.     /*

  373.     Shape of the plane:

  374.            ^             (x,y)

  375.           / \            (x+1,y-1) to (x+1,y+1)

  376.       |---------|        (x+2,y-5) to (x+2,y+5)

  377.            |             (x+3,y)

  378.           ---            (x+4,y-1) to (x+4,y+1)

  379.        @@@@@@@@@         (x+5,y-4) to (x+5,y+4)

  380.       (OOOOOOOOO)

  381.      000000/000000       (x+6,y-6) to (x+6,y+6)  (Blood and full blood)

  382.     */

  383.     int x,y;//position of the head

  384.     int Blood,FullBlood;

  385.     int LastShotTime;

  386.     int ShotSpeed;

  387.     LL Score,BossScore;

  388.     int Buffs[10],GetBuffTime[10];

  389.     double AddAtack,AddShotSpeed;

  390.     int Money;

  391.     int MeetBossTimes;

  392.     void Init(bool isDebug){

  393.         if(isDebug){

  394.             Ammo.clear();

  395.             LastShotTime=-INF;

  396.             /*It shot one time in at most 1000-ShotSpeed ms*/

  397.             ShotSpeed=20;

  398.             Blood=10000,FullBlood=10000;

  399.             x=WINDOWC/2,y=WINDOWW-8;

  400.             Score=BossScore=0;

  401.             AddAtack=AddShotSpeed=50.0;

  402.             MeetBossTimes=1;

  403.             memset(Buffs,0,sizeof Buffs);

  404.         }

  405.         else{

  406.             Ammo.clear();

  407.             LastShotTime=-INF;

  408.             /*It shot one time in at most 1000-ShotSpeed ms*/

  409.             ShotSpeed=500;

  410.             Blood=500,FullBlood=500;

  411.             x=WINDOWC/2,y=WINDOWW-8;

  412.             Score=BossScore=0;

  413.             AddAtack=AddShotSpeed=1.0;

  414.             MeetBossTimes=1;

  415.             memset(Buffs,0,sizeof Buffs);

  416.         }

  417.     }

  418.     bool NeedBoss(){

  419.         if(Score>=ConstBossNeedScore[MeetBossTimes])

  420.             return MeetBossTimes++,1;

  421.         return 0;

  422.     }

  423.     void Flash(int fcolor){

  424.         TP(x,y,fcolor+bwhite,'^');

  425.         TP(x+1,y-1,fcolor+bwhite,'/'),TP(x+1,y+1,fcolor+bwhite,'\\');

  426.         TP(x+2,y-5,fcolor+bwhite,'|');for(int i=y-4;i<=y+4;i++)TP(x+2,i,fcolor+bwhite,'-');TP(x+2,y+5,fcolor+bwhite,'|');

  427.         TP(x+3,y,fcolor+bwhite,'|');

  428.         TP(x+4,y-1,fcolor+bwhite,'-'),TP(x+4,y,fcolor+bwhite,'-'),TP(x+4,y+1,fcolor+bwhite,'-');

  429.         Sleep(200);

  430.         TP(x,y,OC,'^');

  431.         TP(x+1,y-1,OC,'/'),TP(x+1,y+1,OC,'\\');

  432.         TP(x+2,y-5,OC,'|');for(int i=y-4;i<=y+4;i++)TP(x+2,i,OC,'-');TP(x+2,y+5,OC,'|');

  433.         TP(x+3,y,OC,'|');

  434.         TP(x+4,y-1,OC,'-'),TP(x+4,y,OC,'-'),TP(x+4,y+1,OC,'-');

  435.     }

  436.     /*Check if hit only on the body*/

  437.     bool Hit(int tx,int ty){

  438.         return (tx==x&&ty==y)||

  439.                (tx==x+1&&ty>=y-1&&ty<=y+1)||

  440.                (tx==x+2&&ty>=y-5&&ty<=y+5)||

  441.                (tx==x+3&&ty==y)||

  442.                (tx==x+4&&ty>=y-1&&ty<=y+1);

  443.     }

  444.     /*Move the blood line(just move)*/

  445.     /*Remember to check if the position is OK before using*/

  446.     /*And it won't update the plane's position (x and y)*/

  447.     void BloodRefresh(int NewX,int NewY){

  448.         TP(x+5,y-4,OC,"         ");

  449.         TP(x+6,y-6,OC,"             ");

  450.         /*Round up*/

  451.         int FullBlock=(Blood*9+FullBlood-1)/FullBlood;   //Number of "@"

  452.         int EmptyBlock=9-FullBlock;                      //Number of "O"

  453.         int BloodColor=ConstBloodColor[(FullBlock+2)/3];

  454.         /*Print the blood line*/

  455.         for(int i=1;i<=FullBlock;i++)

  456.             TP(NewX+5,NewY-5+i,BloodColor+bblack,'@');

  457.         for(int i=1;i<=EmptyBlock;i++)

  458.             TP(NewX+5,NewY-5+FullBlock+i,fgray+bblack,'O');

  459.         /*Print the blood/fullblood number*/

  460.         /*Due to %06d we can't use TP*/

  461.         gto(NewX+6,NewY-6),color(fgray+bblack),printf("%06d",Blood);

  462.         TP(NewX+6,NewY,OC,'/');

  463.         gto(NewX+6,NewY+1),color(fgray+bblack),printf("%06d",FullBlood);

  464.     }

  465.     /*Move the plane to a new place*/

  466.     void MovePrint(int NewX,int NewY,int flag=1){

  467.         /*Insure that player can control the plane when the mouse is out of screen*/

  468.         NewX=min(NewX,WINDOWC-7);

  469.         NewY=min(max(NewY,6),WINDOWW-7);

  470.         if(flag&&NewX==x&&NewY==y)

  471.             return;

  472.         //gto(WINDOWC-1,0),color(OC),printf("%3d %3d",NewX,NewY);//Debug

  473.         /*Clear the plane in the old position*/

  474.         TP(x,y,OC,' ');

  475.         TP(x+1,y-1,OC,' '),TP(x+1,y+1,OC,' ');

  476.         for(int i=y-5;i<=y+5;i++) TP(x+2,i,OC,' ');

  477.         TP(x+3,y,OC,' ');

  478.         TP(x+4,y-1,OC,' '),TP(x+4,y,OC,' '),TP(x+4,y+1,OC,' ');

  479.         /*Move the blood line*/

  480.         BloodRefresh(NewX,NewY);

  481.         /*Print in the new position*/

  482.         x=NewX,y=NewY;

  483.         TP(x,y,OC,'^');

  484.         TP(x+1,y-1,OC,'/'),TP(x+1,y+1,OC,'\\');

  485.         TP(x+2,y-5,OC,'|');for(int i=y-4;i<=y+4;i++)TP(x+2,i,OC,'-');TP(x+2,y+5,OC,'|');

  486.         TP(x+3,y,OC,'|');

  487.         TP(x+4,y-1,OC,'-'),TP(x+4,y,OC,'-'),TP(x+4,y+1,OC,'-');

  488.         /*Refresh the bullets*/

  489.     }

  490.     void Shot(){

  491.         /*Buff 5*/

  492.         /*Faster shot*/

  493.         int t=clock();

  494.         if(Buffs[5]==1)

  495.             ShotSpeed+=100,Buffs[5]=-1;

  496.         if(Buffs[5]==-1&&t-GetBuffTime[5]>=ConstBuffLastTime[5]){

  497.             ShotSpeed-=100;

  498.             Buffs[5]=0;

  499.             GetBuffTime[5]=0;

  500.         }

  501.         if(!ShotSpeed||LastShotTime>=t-(1000-ShotSpeed*AddShotSpeed))

  502.             return;

  503.         LastShotTime=t;

  504.         if(x>0){

  505.             OwnShotTimes++;

  506.             int Type=1;

  507.             /*Buff 3*/

  508.             /*Get bullets more powerful*/

  509.             if(Buffs[3]){

  510.                 if(t-GetBuffTime[3]>=ConstBuffLastTime[3])

  511.                     Buffs[3]=0,GetBuffTime[3]=0;

  512.                 else

  513.                     Type=3;

  514.             }

  515.             Ammo.insert(new Bullet(1,x-1,y,Type,-1,0));

  516.             /*Buff 1*/

  517.             /*5 lines of bullets*/

  518.             if(Buffs[1]){

  519.                 if(t-GetBuffTime[1]>=ConstBuffLastTime[1]){

  520.                     Buffs[1]=0;

  521.                     GetBuffTime[1]=0;

  522.                     return;

  523.                 }

  524.                 Ammo.insert(new Bullet(1,x-1,y-2,Type,-1,0));

  525.                 Ammo.insert(new Bullet(1,x-1,y-1,Type,-1,0));

  526.                 Ammo.insert(new Bullet(1,x-1,y+1,Type,-1,0));

  527.                 Ammo.insert(new Bullet(1,x-1,y+2,Type,-1,0));

  528.             }

  529.         }

  530.     }

  531. }Own;

  532.  
  533. struct Buff{

  534.     int x,y;

  535.     int Type;

  536.     int DisappearTime;

  537.     Buff(){}

  538.     Buff(int t){x=rand()%(WINDOWC-3)+1,y=rand()%(WINDOWW-2)+1,Type=t,DisappearTime=clock()+ConstBuffAppearTime[t];}

  539. };

  540. set<Buff*> BuffIn;

  541. int LastBuffAppearTime;

  542. int BuffAppearCD=3000;

  543. void BuffRefresh(){

  544.     int T=clock();

  545.     /*New buff in the screen*/

  546.     if(LastBuffAppearTime+BuffAppearCD<=T){

  547.         int id=rand();

  548.         int t=ConstBuffAppearPossibility[BossFlag][id%10];

  549.         if(t)

  550.             BuffIn.insert(new Buff(t));

  551.         LastBuffAppearTime=T;

  552.     }

  553.     vector<set<Buff*>::iterator> Throw;

  554.     for(set<Buff*>::iterator it=BuffIn.begin();it!=BuffIn.end();it++){

  555.         Buff *p=*it;

  556.         TP(p->x,p->y,ConstBuffColor[p->Type],ConstBuffName[p->Type]);

  557.         if(Own.Hit(p->x,p->y)){

  558.             /*Buff 2*/

  559.             /*Recover 100 blood*/

  560.             if(p->Type==2){

  561.                 Own.Blood=min(Own.Blood+100,Own.FullBlood);

  562.                 Own.BloodRefresh(Own.x,Own.y);

  563.             }

  564.             else{

  565.                 Own.Buffs[p->Type]=1;

  566.                 Own.GetBuffTime[p->Type]=T;

  567.             }

  568.             Throw.push_back(it);

  569.             TP(p->x,p->y,OC,' ');

  570.         }

  571.         else if(T>=p->DisappearTime){

  572.             Throw.push_back(it);

  573.             TP(p->x,p->y,OC,' ');

  574.         }

  575.     }

  576.     for(int i=0;i<int(Throw.size());i++)

  577.         BuffIn.erase(Throw[i]);

  578.     //for(int i=1;i<=MAX_BUFF_NUM;i++)

  579.     //    if(Own.Buffs[i]&&clock()-Own.GetBuffTime[i]>=ConstBuffLastTime[i])

  580.     //        Own.Buffs[i]=0;

  581. }

  582.  
  583.  
  584. const char CHART[15]={'|','?','^','&','=','!','@',':','p','\\'};

  585.  
  586. void GameOver(){

  587.     color(OC);

  588.     system("cls");

  589.     /*Get max score before*/

  590.     LL MaxScore=0;

  591.     LL num=((MaxScore*18-2)*38-1314)/2*100+52;

  592.     ifstream R("./MaxScore.sc");

  593.     if(!R.is_open())

  594.         TP(0,0,OC,"ERROR");

  595.     string str;

  596.     R>>str;

  597.     if(str.length()){

  598.         num=0;

  599.         for(int i=0;i<int(str.length());i++)

  600.             if(isdigit(str[i]))

  601.                 num=num*10ll+str[i]-'0';

  602.     }

  603.     R.close();

  604.     /*unlock*/

  605.     MaxScore=(((num-52)/100*2+1314)/38+2)/18;

  606.     TP(WINDOWC/2-2,(WINDOWW+40-10)/2,fred+flight+bblack,"Game Over!");

  607.     TP(WINDOWC/2-1,(WINDOWW+40-15)/2,OC,"Your score: ");

  608.     gto(WINDOWC/2-1,(WINDOWW+40-15)/2+12),color(OC),printf("%08lld",Own.Score+Own.BossScore);

  609.     TP(WINDOWC/2,(WINDOWW+40-15)/2,OC,"MaxScore: ");

  610.     gto(WINDOWC/2,(WINDOWW+40-15)/2+12),color(OC),printf("%08lld",max(Own.Score+Own.BossScore,MaxScore));

  611.     if(Own.Score+Own.BossScore>MaxScore){

  612.         TP(WINDOWC/2+1,(WINDOWW+40-15)/2+2,fred+flight+bblack,"(Refreshed!)"),MaxScore=Own.Score+Own.BossScore;

  613.         /*lock*/

  614.         num=((MaxScore*18-2)*38-1314)/2*100+52;

  615.         string New;

  616.         for(int i=1;i<=30;i++){

  617.             if(rand()%2)

  618.                 New+=CHART[rand()%10];

  619.             else if(num)

  620.                 New+=num%10+'0',num/=10;

  621.         }

  622.         while(num)

  623.             New+=num%10+'0',num/=10;

  624.         while(New.length()<30)

  625.             New+=CHART[rand()%10];

  626.         reverse(New.begin(),New.end());

  627.         fstream CLEAR("./MaxScore.sc", ios::trunc);

  628.         CLEAR.close();

  629.         ofstream T("./MaxScore.sc");

  630.         if(!T.is_open())

  631.             TP(0,0,OC,"ERROR");

  632.         T<<New;

  633.         T.close();

  634.     }

  635.     TP(WINDOWC/2+2,(WINDOWW+40-15)/2-3,OC,"(Press any key to exit)");

  636.     getch();

  637.     gto(WINDOWC/2+4,0),exit(0);

  638. }

  639.  
  640. bool isHit(int,int,int);

  641.  
  642. void MoveBullet(Bullet &me){

  643.     int t=clock();

  644.     if(me.LastBulletRefreshTime>=t-(100-ConstBulletSpeed[me.Type]))

  645.         return;

  646.     me.LastBulletRefreshTime=t;

  647.     int tx=me.x+me.dx,ty=me.y+me.dy;

  648.     TP(me.x,me.y,OC,' ');

  649.     /*It runs out of the screen => erase it*/

  650.     if(tx<0||tx>=WINDOWC||ty<0||ty>=WINDOWW||isHit(tx,ty,me.Type)){

  651.         me.isExist=0;

  652.         return;

  653.     }

  654.     TP(me.x=tx,me.y=ty,ConstBulletColor[me.Type],ConstBulletShape[me.Type]);

  655. }

  656.  
  657. #define MAX_BUFFFULLNAME_LEN 16

  658. const int ConstBuffTipPosition[MAX_BUFF_NUM+5][2]={ {0,0},{13,WINDOWW+3},{14,WINDOWW+3},{15,WINDOWW+3},{16,WINDOWW+3},{17,WINDOWW+3}};

  659. const char ConstBuffFullName[MAX_BUFF_NUM+5][MAX_BUFFFULLNAME_LEN+5]={"","4 more bullets","recover 50 blood","more powerful","double score","shot faster"};

  660. const int ConstMaxBuffFullNameLen[MAX_BUFF_NUM+5]={0,16,16,16,16,16};

  661. void BuffTipRefresh(){

  662.     /*

  663.     TP(12,WINDOWW+3,OC,"---------Details of Buffs---------");

  664.     TP(18,WINDOWW+3,OC,"----------------------------------");

  665.     */

  666.     int C=fgray;

  667.     for(int i=1;i<=MAX_BUFF_NUM;i++){

  668.         TP(ConstBuffTipPosition[i][0],ConstBuffTipPosition[i][1],C,ConstBuffName[i]);

  669.         TP(ConstBuffTipPosition[i][0],ConstBuffTipPosition[i][1]+1,C,": ");

  670.         TP(ConstBuffTipPosition[i][0],ConstBuffTipPosition[i][1]+3,C+(Own.Buffs[i]?bwhite+blight:0),ConstBuffFullName[i]);

  671.         gto(ConstBuffTipPosition[i][0],ConstBuffTipPosition[i][1]+3+ConstMaxBuffFullNameLen[i]),color(C+(Own.Buffs[i]?bwhite+blight:0)),printf("[%02d S]",int(Own.Buffs[i]?(ConstBuffLastTime[i]-(clock()-Own.GetBuffTime[i])+999)/1000:0));

  672.     }

  673. }

  674.  
  675. void EnemyClear(){

  676.     int tmp=UFORefreshTime;

  677.     UFORefreshTime=INF;

  678.     for(set<UFO*>::iterator it=Enemy.begin();it!=Enemy.end();it++)

  679.         (*it)->isExist=0;

  680.     UFORefresh();

  681.     UFORefreshTime=tmp;

  682. }

  683.  
  684. double Performance();

  685.  
  686. //D C B A S

  687. const int PerfColor[10]={fblack+bwhite,fgray+bwhite,fpurple+bwhite,fgreen+bwhite,fred+bwhite};

  688. const char PerfLevel[10][8]={"D.","C.","B.","A!","S!!"};

  689.  
  690. struct BOSS{

  691.     /*Shape of the boss:

  692.       0000000/0000000           (x-7,y-7) to (x-7,y+7)

  693.       @@@@@@@@@@@@@@@           (x-6,y-7) to (x-6,y+7)

  694.      (OOOOOOOOOOOOOOO)

  695.        [-----------]            (x-5,y-6) to (x-5,y+6)

  696.          \OOXXXOO/              (x-4,y-4) to (x-4,y+4)

  697.       +---\XXOXX/---+           (x-3,y-7) to (x-3,y+7)

  698.       V    \OOO/    V           (x-2,y-7) to (x-2,y+7)

  699.             \O/                 (x-1,y-1) to (x-1,y+1)

  700.              V                  (x,y)

  701.     */

  702.     int isExist;

  703.     int x,y;//position of the head

  704.     int dx,dy;

  705.     int Blood,FullBlood;

  706.     int ShotSpeed1,ShotSpeed2,LastShotTime1,LastShotTime2,flag2;

  707.     int MoveSpeed,LastMoveTime;

  708.     int Score,AppearTime;

  709.     int StopCD,StopTime,LastStopTime,isStop;

  710.     int Money;

  711.     bool Hit(int tx,int ty){

  712.         return (tx==x-5&&ty>=y-6&&ty<=y+6)||

  713.                (tx==x-4&&ty>=y-4&&ty<=y+4)||

  714.                (tx==x-3&&ty>=y-7&&ty<=y+7)||

  715.                (tx==x-2&&((ty==y-7)||(ty==y+7)||(ty>=y-2&&ty<=y+2)))||

  716.                (tx==x-1&&ty>=y-1&&ty<=y+1)||

  717.                (tx==x&&ty==y);

  718.     }

  719.     void Die(){

  720.         flash(3);

  721.         BossFlag=0;

  722.         double tmp=Performance();

  723.         int Add=int(Score*tmp);

  724.         Own.BossScore+=Add;

  725.         Own.Money+=Money*(tmp/3.0);

  726.         ScoreFlash=MoneyFlash=1;

  727.         TP(WINDOWC/2-1,WINDOWW/2-18,OC,"+-----------------------------------+");

  728.         TP(WINDOWC/2  ,WINDOWW/2-18,OC,'|'),gto(WINDOWC/2,WINDOWW/2-7),color(PerfColor[int(tmp)]),printf("%s",PerfLevel[int(tmp)]),printf("  + %d scores !",Add),TP(WINDOWC/2  ,WINDOWW/2+18,OC,'|');

  729.         TP(WINDOWC/2+1,WINDOWW/2-18,OC,"+-----------------------------------+");

  730.         Sleep(1500);

  731.         TP(WINDOWC/2-1,WINDOWW/2-18,OC,"                                     ");

  732.         TP(WINDOWC/2  ,WINDOWW/2-18,OC,"                                     ");

  733.         TP(WINDOWC/2+1,WINDOWW/2-18,OC,"                                     ");

  734.         if(x-7>=0) TP(x-7,y-7,OC,"               ");

  735.         if(x-6>=0) TP(x-6,y-7,OC,"               ");

  736.         if(InRange(x)) TP(x,y,OC,' ');

  737.         if(InRange(x-1)) TP(x-1,y-1,OC,"   ");

  738.         if(InRange(x-2)) TP(x-2,y-7,OC,"               ");

  739.         if(InRange(x-3)) TP(x-3,y-7,OC,"               ");

  740.         if(InRange(x-4)) TP(x-4,y-4,OC,"         ");

  741.         if(InRange(x-5)) TP(x-5,y-6,OC,"             ");

  742.         EnemyClear();

  743.     }

  744.     void Flash(){

  745.         if(InRange(x-5)) TP(x-5,y-6,fblack+bwhite,"[-----------]");

  746.         if(InRange(x-4)) TP(x-4,y-4,fblack+bwhite,'\\'),TP(x-4,y-3,fblack+bwhite,"OO"),TP(x-4,y-1,fblack+bwhite,"XXX"),TP(x-4,y+2,fblack+bwhite,"OO"),TP(x-4,y+4,fblack+bwhite,"/");

  747.         if(InRange(x-3)) TP(x-3,y-7,fblack+bwhite,"+---\\XX"),TP(x-3,y,fblack+bwhite,'O'),TP(x-3,y+1,fblack+bwhite,"---+");

  748.         if(InRange(x-2)) TP(x-2,y-7,fblack+bwhite,'V'),TP(x-2,y-2,fblack+bwhite,'\\'),TP(x-2,y-1,fblack+bwhite,"OOO"),TP(x-2,y+2,fblack+bwhite,'/'),TP(x-2,y+7,fblack+bwhite,'V');

  749.         if(InRange(x-1)) TP(x-1,y-1,fblack+bwhite,'\\'),TP(x-1,y,fblack+bwhite,'O'),TP(x-1,y+1,fblack+bwhite,'/');

  750.         if(InRange(x-5)) TP(x-5,y-6,OC,"[-----------]");

  751.         if(InRange(x-4)) TP(x-4,y-4,OC,'\\'),TP(x-4,y-3,fgray+bblack,"OO"),TP(x-4,y-1,OC,"XXX"),TP(x-4,y+2,fgray+bblack,"OO"),TP(x-4,y+4,OC,"/");

  752.         if(InRange(x-3)) TP(x-3,y-7,OC,"+---\\XX"),TP(x-3,y,fgray+bblack,'O'),TP(x-3,y+1,OC,"---+");

  753.         if(InRange(x-2)) TP(x-2,y-7,fgray+bblack,'V'),TP(x-2,y-2,OC,'\\'),TP(x-2,y-1,fgray+bblack,"OOO"),TP(x-2,y+2,OC,'/'),TP(x-2,y+7,fgray+bblack,'V');

  754.         if(InRange(x-1)) TP(x-1,y-1,OC,'\\'),TP(x-1,y,fgray+bblack,'O'),TP(x-1,y+1,OC,'/');

  755.         if(InRange(x)) TP(x,y,OC,' ');

  756.         if(InRange(x)) TP(x,y,OC,'V');

  757.     }

  758.     void Init(int S){

  759.         Blood=FullBlood=ConstBossFullBlood[S];

  760.         x=0,y=rand()%(WINDOWW-14)+7;//Must be in the screen

  761.         dx=1,dy=0;

  762.         LastShotTime1=LastShotTime2=0;

  763.         flag2=0;

  764.         ShotSpeed1=ConstBossShotSpeed[S][0],ShotSpeed2=ConstBossShotSpeed[S][1];

  765.         MoveSpeed=ConstBossMoveSpeed[S];

  766.         LastMoveTime=0;

  767.         Score=ConstBossScore[S];

  768.         AppearTime=clock();

  769.         isExist=1;

  770.         StopTime=ConstBossStopTime[S],StopCD=ConstBossStopCD[S],LastStopTime=isStop=0;

  771.         Money=ConstBossMoney[S];

  772.     }

  773.     void BloodRefresh(int NewX,int NewY){

  774.         /*Print the blood/fullblood number*/

  775.         /*Due to %06d we can't use TP*/

  776.         if(x-7>=0){

  777.             dx=0;

  778.             TP(x-7,y-7,OC,"               ");

  779.             if(isExist){

  780.                 if(NewX-7<WINDOWC){

  781.                     gto(NewX-7,NewY-7),color(fcyan+bblack),printf("%07d",Blood);

  782.                     TP(NewX-7,NewY,fcyan+bblack,'/');

  783.                     gto(NewX-7,NewY+1),color(fcyan+bblack),printf("%07d",FullBlood);

  784.                 }

  785.             }

  786.         }

  787.         /*To appear gradually, we should check the position*/

  788.         if(x-6>=0){

  789.             TP(x-6,y-7,OC,"               ");

  790.             if(isExist)

  791.                 if(NewX-6<WINDOWC){

  792.                     /*Round up*/

  793.                     int FullBlock=(Blood*15+FullBlood-1)/FullBlood;   //Number of "@"

  794.                     int EmptyBlock=15-FullBlock;                       //Number of "O"

  795.                     int BloodColor=ConstBloodColor[(FullBlock+4)/5];

  796.                     /*Print the blood line*/

  797.                     for(int i=1;i<=FullBlock;i++)

  798.                         TP(NewX-6,NewY-8+i,BloodColor+bblack,'@');

  799.                     for(int i=1;i<=EmptyBlock;i++)

  800.                         TP(NewX-6,NewY-8+FullBlock+i,fgray+bblack,'O');

  801.                 }

  802.         }

  803.         if(x-7>=WINDOWC)

  804.             isExist=0;

  805.     }

  806.     /*Only one boss so we don't have to make the function out*/

  807.     void MovePrint(){

  808.         int t=clock();

  809.         if(LastMoveTime>=t-(1000-MoveSpeed))

  810.             return;

  811.         LastMoveTime=t;

  812.         /*Change the direction*/

  813.         if(rand()%10==0)

  814.             dy=ConstNewDy[rand()%3];

  815.         int NewX=x+dx,NewY=y+dy;

  816.         if(UFOCrash(NewX,NewY)||NewY-7<0||NewY+7>=WINDOWW)

  817.             for(int i=0;i<3;i++){

  818.                 dy=ConstNewDy[rand()%3];

  819.                 NewX=x+dx,NewY=y+dy;

  820.                 if(!(UFOCrash(NewX,NewY)||NewY-7<0||NewY+7>=WINDOWW))

  821.                     break;

  822.             }

  823.         if(UFOCrash(NewX,NewY)||NewY-7<0||NewY+7>=WINDOWW)

  824.             return;

  825.         if(InRange(x)) TP(x,y,OC,' ');

  826.         if(InRange(NewX)) TP(NewX,NewY,OC,'V');

  827.         if(InRange(x-1)) TP(x-1,y-1,OC,"   ");

  828.         if(InRange(NewX-1))

  829.             TP(NewX-1,NewY-1,OC,'\\'),

  830.             TP(NewX-1,NewY,fgray+bblack,'O'),

  831.             TP(NewX-1,NewY+1,OC,'/');

  832.         if(InRange(x-2)) TP(x-2,y-7,OC,"               ");

  833.         if(InRange(NewX-2)) TP(NewX-2,NewY-7,fgray+bblack,'V'),TP(NewX-2,NewY-2,OC,'\\'),TP(NewX-2,NewY-1,fgray+bblack,"OOO"),TP(NewX-2,NewY+2,OC,'/'),TP(NewX-2,NewY+7,fgray+bblack,'V');

  834.         if(InRange(x-3)) TP(x-3,y-7,OC,"               ");

  835.         if(InRange(NewX-3)) TP(NewX-3,NewY-7,OC,"+---\\XX"),TP(NewX-3,NewY,fgray+bblack,'O'),TP(NewX-3,NewY+1,OC,"XX/---+");

  836.         if(InRange(x-4)) TP(x-4,y-4,OC,"         ");

  837.         if(InRange(NewX-4)) TP(NewX-4,NewY-4,OC,'\\'),TP(NewX-4,NewY-3,fgray+bblack,"OO"),TP(NewX-4,NewY-1,OC,"XXX"),TP(NewX-4,NewY+2,fgray+bblack,"OO"),TP(NewX-4,NewY+4,OC,"/");

  838.         if(InRange(x-5)) TP(x-5,y-6,OC,"             ");

  839.         if(InRange(NewX-5)) TP(NewX-5,NewY-6,OC,"[-----------]");

  840.         BloodRefresh(NewX,NewY);

  841.         x=NewX,y=NewY;

  842.     }

  843.     void Shot(){

  844.         int t=clock();

  845.         if(LastShotTime1<t-(100-ShotSpeed1)){

  846.             LastShotTime1=t;

  847.             if(x-1>=0){

  848.                 Ammo.insert(new Bullet(1,x-1,y-7,4,1,0));

  849.                 Ammo.insert(new Bullet(1,x-1,y+7,4,1,0));

  850.             }

  851.         }

  852.         if(LastShotTime2<t-(100-ShotSpeed2-500)){

  853.             LastShotTime2=t,flag2=1;

  854.             TP(x,y,fred+flight+bgray,'V');

  855.         }

  856.         if(flag2&&t>=LastShotTime2+500){

  857.             flag2=0;

  858.             if(x+1>=0)

  859.                 Ammo.insert(new Bullet(1,x+1,y,5,1,0));

  860.         }

  861.     }

  862. }Boss;

  863.  
  864. /*There's an awful problem that set<UFO*>Enemy will be use in the struct UFO but it needs the declaration of struct UFO so we can neither put it in front of the struct UFO nor put it after the struct UFO...*/

  865. /*So we have to get the function Crash out of the struct UFO.*/ /*Eating shit*/

  866. /*To check if it will hit another UFO*/

  867. void UFOMovePrint(UFO&,set<UFO*>::iterator);

  868. bool UFOCrash(UFO me,int NewX,int NewY,set<UFO*>::iterator ID){

  869.     for(set<UFO*>::iterator it=Enemy.begin();it!=Enemy.end();it++){

  870.         int ox=(*it)->x,oy=(*it)->y;

  871.         if(it==ID||ox<NewX) continue;

  872.         if(NewX<=ox+4&&NewX>=ox-4&&NewY>=oy-8&&NewY<=oy+8){

  873.             /*avoid disfluency*/

  874.             UFO *New=*it;

  875.             UFOMovePrint(*New,it);

  876.             return 1;

  877.         }

  878.     }

  879.     if(BossFlag&&NewX<=Boss.x&&NewX>=Boss.x-5&&NewY>=Boss.y-9&&NewY<=Boss.y+9)

  880.         return 1;

  881.     return 0;

  882. }

  883. bool UFOCrash(int NewX,int NewY){

  884.     for(set<UFO*>::iterator it=Enemy.begin();it!=Enemy.end();it++){

  885.         int ox=(*it)->x,oy=(*it)->y;

  886.         if(ox<NewX) continue;

  887.         if(NewX<=ox+9&&NewX>=ox-9&&NewY>=oy-9&&NewY<=oy+9)

  888.             return 1;

  889.     }

  890.     return 0;

  891. }

  892.  
  893. //OwnShotTimes,OwnLoseBlood,OwnShotOnTimes;

  894. double Performance(){//(0,5]

  895.     double p1=double(OwnShotOnTimes)/max(OwnShotTimes,1);

  896.     double p2=max(double(Own.FullBlood-OwnLoseBlood)/Own.FullBlood,0.0);

  897.     return min((p1+p2)*2.5,4.999999);

  898. }

  899.  
  900. void BossRefresh(){

  901.     Boss.MovePrint();

  902.     int t=clock();

  903.     if(!Boss.isStop)

  904.         Boss.Shot();

  905.     if(!Boss.isStop&&Boss.LastStopTime+Boss.StopTime+Boss.StopCD<=t)

  906.         Boss.LastStopTime=t,Boss.isStop=1;

  907.     if(Boss.isStop&&t-Boss.LastStopTime>=Boss.StopTime)

  908.         Boss.isStop=0;

  909. }

  910.  
  911. void Init(){

  912.     srand((unsigned)time(NULL));

  913.     //SetWindow("HPF",WINDOWC+12,WINDOWW+45,0,500);

  914.     SetWindow("HPF",WINDOWC+2,WINDOWW+40);

  915.     HindCursor();

  916.     TP(0,0,OC,"+---------------------------------------------------------------------------------------------+");

  917.     TP(2,(WINDOWW+40)/2-7,OC,"Hape Flying Game");

  918.     TP(7,0,OC,"+---------------------------------------------------------------------------------------------+");

  919.     Button Start=NewButton(4,(WINDOWW+40)/2-4,OC,"> Start <");

  920.     Button More=NewButton(5,(WINDOWW+40)/2-4,OC,"> More  <");

  921.     while(1){

  922.         if(Preserve(Start)){

  923.             Own.Init(0);

  924.             break;

  925.         }

  926.         if(Preserve(More)){

  927.             TP(6,3,fred,"Input the password: ");

  928.             gto(6,22),color(fgray);

  929.             char Key[15];

  930.             fgets(Key,10,stdin);

  931.             if(!strcmp(Key,"cxhsdsb\n")){

  932.                 Own.Init(1);

  933.                 break;

  934.             }

  935.             fflush(stdin);

  936.             color(OC);

  937.             system("cls");

  938.             TP(0,0,OC,"+---------------------------------------------------------------------------------------------+");

  939.             TP(2,(WINDOWW+40)/2-7,OC,"Hape Flying Game");

  940.             TP(7,0,OC,"+---------------------------------------------------------------------------------------------+");

  941.         }

  942.         Sleep(50);

  943.     }

  944.     color(OC);

  945.     system("cls");

  946. }

  947.  
  948. /*Meet the awful problem again*/

  949. bool isHit(int NewX,int NewY,int Type){

  950.     if(Type==1||Type==3){

  951.         int DM=int(ConstBulletDamage[Type]*Own.AddAtack);

  952.         for(set<UFO*>::iterator it=Enemy.begin();it!=Enemy.end();it++){

  953.             if((*it)->Hit(NewX,NewY)){

  954.                 /*Mention the order, or it won't be cleared*/

  955.                 UFO *t=*it;

  956.                 t->Flash();

  957.                 t->Blood=max(t->Blood-DM,0);

  958.                 t->BloodRefresh(t->x,t->y);

  959.                 if(t->Blood<=0){

  960.                     Own.Money+=t->Money;

  961.                     MoneyFlash=1;

  962.                     ScoreFlash=1;

  963.                     t->isExist=0;

  964.                     t->ClearPrint();

  965.                     int Add=t->Score;

  966.                     /*Buff 4*/

  967.                     /*Double score*/

  968.                     if(Own.Buffs[4]){

  969.                         if(Own.GetBuffTime[4]+ConstBuffLastTime[4]>=clock()){

  970.                             Own.Buffs[4]=0;

  971.                             Own.GetBuffTime[4]=0;

  972.                         }

  973.                         Add+=t->Score;

  974.                     }

  975.                     if(BossFlag)

  976.                         Add/=10;

  977.                     Own.Score+=Add;

  978.                 }

  979.                 return 1;

  980.             }

  981.         }

  982.         if(BossFlag&&Boss.Hit(NewX,NewY)){

  983.             Boss.Flash();

  984.             Boss.Blood=max(Boss.Blood-DM/2,0);

  985.             Boss.BloodRefresh(Boss.x,Boss.y);

  986.             OwnShotOnTimes++;

  987.             if(Boss.Blood<=0)

  988.                 Boss.Die(),BossFlag=0;

  989.             return 1;

  990.         }

  991.     }

  992.     else if(Own.Hit(NewX,NewY)){

  993.         Own.Flash(fred+flight);

  994.         OwnLoseBlood+=min(Own.Blood,ConstBulletDamage[Type]);

  995.         Own.Blood=max(Own.Blood-ConstBulletDamage[Type],0);

  996.         Own.BloodRefresh(Own.x,Own.y);

  997.         if(Own.Blood<=0)

  998.             GameOver();

  999.         return 1;

  1000.     }

  1001.     return 0;

  1002. }

  1003.  
  1004. #define MAX_GRADE 10

  1005. const int ConstUpgradeCost[MAX_GRADE+5]={10,20,50,100,200,500,1000,2000,5000,10000,INF};

  1006. const char ConstUpgradeCostStr[MAX_GRADE+5][10]={"(M 10)","(M 20)","(M 50)","(M 100)","(M 200)","(M 500)","(M 1000)","(M 2000)","(M 5000)","(M 10000)","(M INF)  "};

  1007. const int ConstGradeColor[MAX_GRADE+5]={fgreen+flight+bblack,fgreen+flight+bblack,fgreen+bblack,fblue+flight+bblack,fblue+flight+bblack,fblue+bblack,fyellow+flight+bblack,fyellow+bblack,fyellow+bblack,fred+flight+bblack,fred+bblack,fred+bblack};

  1008. const char ConstGradeName[MAX_GRADE+5][20]={"[G0]","[G1]","[G2]","[G3]","[G4]","[G5]","[G6]","[G7]","[G8]","[G9]","[G10]"};

  1009.  
  1010. int main(){

  1011.     //GameOver();

  1012.     //ColorPrint();

  1013.     //getchar();

  1014.     Init();

  1015.     HWND hd;

  1016.     hd=GetForegroundWindow();

  1017.     TP(12,WINDOWW+3,OC,"---------Details of Buffs---------");

  1018.     TP(18,WINDOWW+3,OC,"----------------------------------");

  1019.     //Own.Blood=100;

  1020.     int cnt=1;

  1021.     BossFlag=0;

  1022.     int LastT=clock()/1000-2,LastMoney=-1;

  1023.     BEGINTIME=clock();

  1024.     int _____=0,STOP=0,LastPreserveTime=-INF;

  1025.  
  1026.     Button AddFullBlood,AddAttack,AddShotSpeed;

  1027.     int FullBloodGrade=0,AttackGrade=0,ShotSpeedGrade=0;

  1028.     string AddFullBloodTip("> Add your max blood by 500"),AddAttackTip("> Add your attack by 10%"),AddShotSpeedTip("> Add your shot speed by 10%");

  1029.     AddFullBlood=NewButton(5,WINDOWW+3,OC,"> Add your max blood by 200");

  1030.     AddAttack=NewButton(6,WINDOWW+3,OC,"> Add your attack by 10%");

  1031.     AddShotSpeed=NewButton(7,WINDOWW+3,OC,"> Add your shot speed by 5%");

  1032.     //Own.Money=10000000;

  1033.     while(1){

  1034.         if(!STOP){

  1035.             if(_____%10==0){

  1036.                 gto(0,0),color(OC);

  1037.                 for(int i=1;i<=WINDOWW+40;i++)

  1038.                     putchar('-');

  1039.                 gto(WINDOWC,0),color(OC);

  1040.                 for(int i=1;i<=WINDOWW+40;i++)

  1041.                     putchar('-');

  1042.             }

  1043.             _____++;

  1044.             POINT k;

  1045.             GetPos(k);

  1046.             Own.MovePrint(min(max(int(k.x)-3,1),WINDOWC-1),min(max(int(k.y),0),WINDOWW-1));

  1047.             if(KEY_DOWN(MOUSE_MOVED))

  1048.                 Own.Shot();

  1049.             BulletsRefresh();

  1050.             if(BossFlag)

  1051.                 BossRefresh();

  1052.             UFORefresh();

  1053.             BuffRefresh(),BuffTipRefresh();

  1054.             if(ScoreFlash){

  1055.                 ScoreFlash=0;

  1056.                 TP(10,WINDOWW+3,fred+flight+bwhite,"[ "),

  1057.                 TP(10,WINDOWW+5,OC-bblack+bwhite,"Score: "),

  1058.                 gto(10,WINDOWW+12),color(OC-bblack+bwhite),printf("%04lld + %08lld",Own.Score,Own.BossScore),

  1059.                 TP(10,WINDOWW+27,fred+flight+bwhite," ]");

  1060.                 Sleep(100);

  1061.             }

  1062.             TP(10,WINDOWW+3,fred+flight+bblack,"[ "),

  1063.             TP(10,WINDOWW+5,OC,"Score: "),

  1064.             gto(10,WINDOWW+12),color(OC),printf("%04lld + %08lld",Own.Score,Own.BossScore),

  1065.             TP(10,WINDOWW+27,fred+flight+bblack," ]");

  1066.             int T=(clock()-BEGINTIME)/1000;

  1067.             if(T!=LastT){

  1068.                 TP(9,WINDOWW+3,fred+flight+bblack,"[ "),TP(9,WINDOWW+5,OC,"Time: "),gto(9,WINDOWW+11),color(OC),printf("%05d",T),TP(9,WINDOWW+16,fred+flight+bblack," ]");

  1069.                 LastT=T;

  1070.             }

  1071.         }

  1072.         if(Own.Money!=LastMoney){

  1073.             if(MoneyFlash){

  1074.                 MoneyFlash=0;

  1075.                 TP(1,WINDOWW+3,fred+flight+bwhite,"[ "),

  1076.                 TP(1,WINDOWW+6,OC-bblack+bwhite,"Money: "),

  1077.                 gto(1,WINDOWW+13),color(OC-bblack+bwhite),printf("%08d",LastMoney=Own.Money),

  1078.                 TP(1,WINDOWW+21,fred+flight+bwhite," ]");

  1079.                 Sleep(100);

  1080.             }

  1081.             TP(1,WINDOWW+3,fred+flight+bblack,"[ "),

  1082.             TP(1,WINDOWW+6,OC,"Money: "),

  1083.             gto(1,WINDOWW+13),color(OC),printf("%08d",LastMoney=Own.Money),

  1084.             TP(1,WINDOWW+21,fred+flight+bblack," ]");

  1085.  
  1086.         }

  1087.         if(clock()-LastPreserveTime>=100){

  1088.             LastPreserveTime=clock();

  1089.             if(Preserve(AddFullBlood)){

  1090.                 if(Own.Money>=ConstUpgradeCost[FullBloodGrade]){

  1091.                     Own.Money-=ConstUpgradeCost[FullBloodGrade];

  1092.                     Own.FullBlood+=200;

  1093.                     MoneyFlash=1;

  1094.                     FullBloodGrade++;

  1095.                 }

  1096.             }

  1097.             if(Preserve(AddAttack)){

  1098.                 if(Own.Money>=ConstUpgradeCost[AttackGrade]){

  1099.                     Own.Money-=ConstUpgradeCost[AttackGrade];

  1100.                     Own.AddAtack+=0.1;

  1101.                     MoneyFlash=1;

  1102.                     AttackGrade++;

  1103.                 }

  1104.             }

  1105.             if(Preserve(AddShotSpeed)){

  1106.                 if(Own.Money>=ConstUpgradeCost[ShotSpeedGrade]){

  1107.                     Own.Money-=ConstUpgradeCost[ShotSpeedGrade];

  1108.                     Own.AddShotSpeed+=0.05;

  1109.                     MoneyFlash=1;

  1110.                     ShotSpeedGrade++;

  1111.                 }

  1112.             }

  1113.             TP(5,WINDOWW+31,ConstGradeColor[FullBloodGrade+1],ConstUpgradeCostStr[FullBloodGrade]);

  1114.             TP(2,WINDOWW+3,OC,"Max Blood: "),gto(2,WINDOWW+18),color(OC),printf("%06d",Own.FullBlood);

  1115.             TP(2,WINDOWW+25,ConstGradeColor[FullBloodGrade],ConstGradeName[FullBloodGrade]);

  1116.             Own.MovePrint(Own.x,Own.y,0);

  1117.             TP(6,WINDOWW+31,ConstGradeColor[AttackGrade+1],ConstUpgradeCostStr[AttackGrade]);

  1118.             TP(3,WINDOWW+3,OC,"Attack: "),gto(3,WINDOWW+18),color(OC),printf("%06d",int((Own.Buffs[3]?ConstBulletDamage[3]:ConstBulletDamage[1])*Own.AddAtack));

  1119.             TP(3,WINDOWW+25,ConstGradeColor[AttackGrade],ConstGradeName[AttackGrade]);

  1120.             TP(7,WINDOWW+31,ConstGradeColor[ShotSpeedGrade+1],ConstUpgradeCostStr[ShotSpeedGrade]);

  1121.             TP(4,WINDOWW+3,OC,"Attack Speed: "),gto(4,WINDOWW+18),color(OC),printf("%06d",int(Own.ShotSpeed*Own.AddShotSpeed));

  1122.             TP(4,WINDOWW+25,ConstGradeColor[ShotSpeedGrade],ConstGradeName[ShotSpeedGrade]);

  1123.         }

  1124.         if(kbhit()){

  1125.             char c=getch();

  1126.             if(c==' '){

  1127.                 if(!STOP){

  1128.                     TP(WINDOWC/2-1,WINDOWW/2-16,OC,"+----------------------------------+");

  1129.                     TP(WINDOWC/2  ,WINDOWW/2-16,OC,"|   Press space bar to continue.   |");

  1130.                     TP(WINDOWC/2+1,WINDOWW/2-16,OC,"+----------------------------------+");

  1131.                     STOP=1;

  1132.                 }

  1133.                 else{

  1134.                     TP(WINDOWC/2-1,WINDOWW/2-16,OC,"                                    ");

  1135.                     TP(WINDOWC/2  ,WINDOWW/2-16,OC,"                                    ");

  1136.                     TP(WINDOWC/2+1,WINDOWW/2-16,OC,"                                    ");

  1137.                     STOP=0;

  1138.                     RECT W;

  1139.                     GetWindowRect(hd,&W);

  1140.                     SetCursorPos(W.left+Own.y*8+10,W.top+Own.x*16+80);

  1141.                 }

  1142.             }

  1143.         }

  1144.         /*Boos*/

  1145.         if(!BossFlag&&Own.NeedBoss()){

  1146.         //if(!BossFlag)

  1147.             Sleep(200);

  1148.             flash(3);

  1149.             OwnShotTimes=OwnLoseBlood=OwnShotOnTimes=0;

  1150.             EnemyClear();

  1151.             //UFORefreshTime=5000;

  1152.             //BuffAppearCD=5000;

  1153.             Boss.Init(cnt);

  1154.             BossFlag=1;

  1155.             cnt++;

  1156.         }

  1157.     }

  1158. }

最后

原创不易,燃烧秀发输出内容,如果有一丢丢收获,点个赞鼓励一下吧!还有个小惊喜,帮大家整理了一些技术电子书,关注公众号《AIO生活》回复“1024”即可获取~

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/jourey_for_you/article/details/103385341

智能推荐

ASP.Net Core Razor 部署AdminLTE框架-程序员宅基地

文章浏览阅读381次。1、AdminLTE一个基于 bootstrap 的轻量级后台模板2、AdminLTE 文档在线中文Demo:http://adminlte.la998.com/在线中文文档:http://adminlte.la998.com/documentation/index.htmlGithub:https://github.com/almasaeed2010/AdminLTE/r..._.net razor adminlte

linux中iconv函数报错,Linux下编码转换(iconv函数族)-程序员宅基地

文章浏览阅读539次。转自:http://www.linuxdiyf.com/viewarticle.php?id=45164在Linux上进行编码转换时,既可以利用iconv函数族编程实现,也可以利用iconv命令来实现(针对文件进行转换)一、利用iconv函数族进行编码转换iconv函数族的头文件是iconv.h使用前需包含之:#include iconv函数族有三个函数,原型如下:(1) iconv_open()..._报错iconv:conversion to ‘gb2321’ is not supported

sharding-jdbc和sharding-proxy使用_shardingjdbc和shardingproxy如何选择-程序员宅基地

文章浏览阅读2k次。sharding-jdbc和sharding-proxy使用sharding-jdbc使用本项目选择sharding-jdbc作为分表分库的组件sharding-jdbc后续发展为Sharding-Sphere,包含sharding-jdbc、Sharding-Proxy、Sharding-Sidecar定位为轻量级Java框架,在Java的JDBC层提供的额外服务。 它使用客户端直连数据库,以jar包形式提供服务,需额外部署和依赖,可理解为增强版的JDBC驱动,完全兼容JDBC和各种ORM框架。_shardingjdbc和shardingproxy如何选择

基于野马算法优化概率神经网络PNN的分类预测 - 附代码_野马优化算法的应用有哪些-程序员宅基地

文章浏览阅读50次。概率神经网络( probabilistic neural networks , PNN )是 D. F. Specht 博士在 1 989 年首先提出的,是一种基于 Bayes 分类规则与 Parzen窗的概率密度面数估计方法发展而来的并行算 法。它是一类结胸简单、训练简洁、应用广泛的人工神经网络。在实际应用中,尤其是在解决分类问题的应用中, PNN 的优势在于用线性学习算法来完成非线性学 习算法所傲的工作,同 时保持非线性算法的高精度等特性;_野马优化算法的应用有哪些

程序员专属情人节表白网站HTML+CSS+JavaScript-程序员宅基地

文章浏览阅读489次,点赞10次,收藏8次。网站程序方面:计划采用最新的网页编程语言HTML5+CSS3+JS程序语言完成网站的功能设计。并确保网站代码兼容目前市面上所有的主流浏览器,已达到打开后就能即时看到网站的效果。网站文件方面:网站系统文件种类包含:html网页结构文件、css网页样式文件、js网页特效文件、images网页图片文件;

个人博客开通TEST-程序员宅基地

文章浏览阅读46次。个人博客开通TEST个人博客开通TEST个人博客开通TEST个人博客开通TEST个人博客开通TEST

随便推点

(3)二分频systemverilog与VHDL编码_vhdl二分频器代码-程序员宅基地

文章浏览阅读314次。3二分频systemverilog与VHDL编码1 本章目录1)FPGA简介2)Verilog简介3)VHDL简介4)二分频SystemVerilog编码5)二分频VHDL编码6)结束语2 FPGA简介FPGA(Field Programmable Gate Array)是在PAL、GAL等可编程器件的基础上进一步发展的产物。它是作为专用集成电路(ASIC)领域中的一种半定制电路而出现的,既解决了定制电路的不足,又克服了原有可编程器件门电路数有限的缺点。FPGA设计不_vhdl二分频器代码

“零前瞻”AI寻迹小车,如何跑出20厘米前瞻效果的_寻迹目标点反解算双轮速度-程序员宅基地

文章浏览阅读6.1k次,点赞20次,收藏212次。ACE参赛队伍2020-09-15 Tuesday ● 摘要本文详细介绍了山东大学(威海)ACE队在第十五届全国大学生智能汽车竞赛AI电磁组中的系统方案。内容包括AI小车的系统的原理、软硬件方案设计以及神经网络模型的生成过程。本次比赛采用大赛组委会统一指定的C型车模,AI小车以单片机MIMXRT1064DVL6A为控制核心,用电感采集赛道信息,编码器获取小车的速度。使用 IAR 及keil5集成编译环境编写C语言代码,采用PyCharm作为编译器,使用Python程序语._寻迹目标点反解算双轮速度

《Qt5:Widget、Dialog和MainWindow之间的关系》_widgets和mainwindow-程序员宅基地

文章浏览阅读8.5k次,点赞9次,收藏31次。目录概述官方文档Widget(小部件)MainWindow(主窗口)Dialog(对话框)概述Widget翻译过来是小部件的意思,Widget、Dialog和MainWindow三者都可以独立创建用户界面。QWidget类是所有用户界面对象的基类,QMainWindow和QDialog其实就是QWidget的子类,唯一有点血缘关系的就是继承了QWidget类,..._widgets和mainwindow

php获取正文中所有图片_php 获取内容里边所有图片-程序员宅基地

文章浏览阅读1.1w次。代码/** * Notes:获取文本中所以图片 * @auther: xxf * Date: 2019/7/25 * Time: 13:55 * @param $content * @param int $order 第几张,0全部 * @return array */function getImages($content,$order=0){ $pattern="..._php 获取内容里边所有图片

css3直线运动_用纯CSS3制作的效果非常炫酷的元素边框线条动画特效-程序员宅基地

文章浏览阅读424次。插件描述:这是一款使用纯CSS3制作的效果非常炫酷的元素边框线条动画特效。这个元素边框线条动画使用伪元素和keyframes来制作线条运动效果。这是一款使用纯CSS3制作的效果非常炫酷的元素边框线条动画特效。这个元素边框线条动画使用伪元素和keyframes来制作线条运动效果。制作方法HTML结构该边框线条动画特效的HTML结构使用的是一个空的来作为容器。CSS样式该边框线条动画特效的两条动画的线..._css3 线条特效

Java 基础学习记录_打电话出现对照符号提示什么-程序员宅基地

文章浏览阅读803次。Java 基础DAY11、关于进制的运算2、关于存储单元3、关于CMD的基本命令4、JRE与JDK5、Java环境变量6、程序开发步骤7、HelloWorld8、标识符9、常量10、数据类型数据类型分类基本数据类型注意事项:11、变量DAY21、数据类型转换自动类型转换(隐式)强制类型转换(显式)2、ASCII编码表3、算术运算符四则运算当中的加号“+”有常见的三种用法:4、自增自减运算符5、赋值..._打电话出现对照符号提示什么

推荐文章

热门文章

相关标签