蒟蒻打的飞机大战1.0(简单易懂)
#include<conio.h>
#include<windows.h>
#include<bits/stdc++.h>
using namespace std;
struct location{
short y,x;
}plane,fighter;
queue<location>bullet;
void slowout(string str){
for(int i=0;i<str.length();i++){
printf("%c",str[i]);
Sleep(30);
}
}
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
int game_difficulty;
long long kill_time=0,history_score;
bool robot_play,fighter_live;
int main(){
system("color 9F");
slowout("现在是公元2032年,战争时期!");
Sleep(1000);
slowout("数百架六代敌机从十艘福特级航母上一架架的起飞,此刻的您已经发射完了所有的导弹,剩下的武器只有一台机炮,");
Sleep(1000);
slowout("但是为了祖国,为了世界的核平!");
Sleep(1000);
slowout("同时也为了您自己,您必须保证没有一架敌机突防!\n\n");
Sleep(1000);
slowout("操作指南(极简版):");
Sleep(500);
slowout("w,a,s,d\n");
printf("请按r欣赏机器示范或按其他任意键开始游戏...");
srand(time(0));
char c=getch();
if(c=='R'||c=='r'){
robot_play=true;
MessageBox(0,"在示范过程中,您可以按任意键结束示范。","小贴士",MB_OK);
}while(true){
plane.y=20,plane.x=40;
fighter.y=0,fighter.x=30;
fighter_live=true;
kill_time=0;
while(true){
system("cls");
coord.Y=0,coord.X=70;
SetConsoleCursorPosition(hout,coord);
printf("Your kill:%lld",kill_time);
++coord.Y,coord.X=70;
SetConsoleCursorPosition(hout,coord);
printf("Your score:%lld",kill_time*(kill_time+1)/2);
++coord.Y,coord.X=70;
SetConsoleCursorPosition(hout,coord);
printf("Your history score:%lld",history_score=max(history_score,kill_time*(kill_time+1)/2));
coord.Y=plane.y,coord.X=plane.x;
SetConsoleCursorPosition(hout,coord);
printf("|");
++coord.Y,coord.X=plane.x-1;
SetConsoleCursorPosition(hout,coord);
printf("/|\\");
++coord.Y,coord.X=plane.x-2;
SetConsoleCursorPosition(hout,coord);
printf("/|||\\");
++coord.Y,coord.X=plane.x-3;
SetConsoleCursorPosition(hout,coord);
printf("=======");
coord.Y=fighter.y;
coord.X=fighter.x-3;
SetConsoleCursorPosition(hout,coord);
printf("=======");
++coord.Y,coord.X=fighter.x-2;
SetConsoleCursorPosition(hout,coord);
printf("\\\\|//");
++coord.Y,coord.X=fighter.x-1;
SetConsoleCursorPosition(hout,coord);
printf("\\|/");
++coord.Y,coord.X=fighter.x;
SetConsoleCursorPosition(hout,coord);
printf("|");
if(plane.y){
location new_bullet;
new_bullet.y=plane.y-1,new_bullet.x=plane.x;
bullet.push(new_bullet);
}
for(int i=1;i<=bullet.size();i++){
location tmp=bullet.front();
bullet.pop();
coord.Y=tmp.y,coord.X=tmp.x;
SetConsoleCursorPosition(hout,coord);
printf(".");
if(tmp.y==fighter.y+4&&tmp.x>=fighter.x-1&&tmp.x<=fighter.x+2||tmp.y==fighter.y+3&&tmp.x>=fighter.x-2&&tmp.x<=fighter.x+3||tmp.y==fighter.y+2&&tmp.x>=fighter.x-3&&tmp.x<=fighter.x+4||tmp.y==fighter.y+1&&tmp.x>=fighter.x-4&&tmp.x<=fighter.x+5||tmp.y==fighter.y&&tmp.x>=fighter.x-5&&tmp.x<=fighter.x+6){
fighter_live=false;
++kill_time;
}
if(tmp.y){
--tmp.y;
bullet.push(tmp);
}
}
if(kbhit()){
char c=getch();
if(robot_play){
break;
}if(c=='d'||c=='D'){
if(plane.x<=55){
plane.x+=2;
}
}else if(c=='a'||c=='A'){
if(plane.x>=5){
plane.x-=2;
}
}else if(c=='s'||c=='S'){
if(plane.y<=35){
plane.y+=2;
}
}else if(c=='w'||c=='W'){
if(plane.y>=2){
plane.y-=2;
}
}
}
if(robot_play){
if(plane.y<35){
++plane.y;
}else if(plane.x<fighter.x){
++plane.x;
}else if(plane.x>fighter.x){
--plane.x;
}
}
if(!fighter_live){
fighter.x=rand()%44+3,fighter.y=0;
fighter_live=true;
}
if(++game_difficulty>=max(20-kill_time/2,(long long)4)){
game_difficulty=0;
if(fighter.y<47){
++fighter.y;
}else{
Sleep(3000);
break;
}
}
}system("cls");
printf("You lose!\nYour kill:%lld\nYour score:%lld",kill_time,kill_time*(kill_time+1)/2);
history_score=max(history_score,kill_time*(kill_time+1)/2);
printf("\n\nAnd your history score is:%lld\n\n请按r欣赏机器示范或按其他任意键继续游戏......",history_score);
char c=getch();
if(c=='R'||c=='r'){
robot_play=true;
}else{
robot_play=false;
}
}return 0;
}