跳到正文

剪贴板

剪贴板 egr7d31n

JohnShu
原文
剪贴板信息

剪贴板信息

发布
收录
更新

✈️飞机大战 v3.0+ | 开源休闲控制台游戏开源代码

✈️飞机大战v3.1代码

C++
#include<iostream>
#include<windows.h>
#include<mmsystem.h>
#include<conio.h>
#include<time.h>
#include<string>
using namespace std;

#define ENEMY_NORMAL 0
#define ENEMY_FAST   1
#define ENEMY_HEAVY  2
#define ENEMY_SHOOT  3
#define ENEMY_PLUS   4

typedef struct Frame
{
	COORD position[2];
	COORD oldPos[2];
	int flag;
	int type;
	int hp;
	int explodeTimer;
}Frame;

void DisableQuickEdit()
{
	HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
	DWORD mode;
	GetConsoleMode(hConsole, &mode);
	mode &= ~ENABLE_QUICK_EDIT_MODE;
	SetConsoleMode(hConsole, mode);
}

//音效与BGM函数
void PlayTitleEnterSound()
{
	PlaySoundA("title.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_NOSTOP);
}
void PlayUltSound()
{
	PlaySoundA("ult.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_NOSTOP);
}
void PlaySelectSound(){
	PlaySoundA("select.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_NOSTOP);
}
void PlayPlaneMoveSound(){
	PlaySoundA("move.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_NOSTOP);
}
void PlayExplodeSound(){
	PlaySoundA("boom.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_NOSTOP);
}
void PlayCrashSound(){
	PlaySoundA("crash.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_NOSTOP);
}
void PlayHitSound(){
	PlaySoundA("hit.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_NOSTOP);
}
void PlayBossAppear()
{
	PlaySoundA("boss_appear.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_NOSTOP);
}
void PlayBossWarning()
{
	PlaySoundA("boss_warn.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_NOSTOP);
}
void PlayWinSound()
{
	PlaySoundA("win.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_NOSTOP);
}

//菜单背景音乐(bgm.wav才是循环音乐,title.wav是进入音效,移除循环)
void StartHelpBGM()
{
	PlaySoundA("bgm.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_LOOP);
}
//对局战斗循环音乐
void StartBattleBGM()
{
	PlaySoundA("bgm.wav", NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT | SND_LOOP);
}
void StopAllSound()
{
	PlaySoundA(NULL, NULL, 0);
}

void SetPos(COORD a)
{
	HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(out, a);
}
void SetPos(int i, int j)
{
	COORD pos = { (short)i, (short)j };
	SetPos(pos);
}
void HideCursor()
{
	CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void drawRow(int y, int x1, int x2, char ch)
{
	SetPos(x1, y);
	for (int i = 0; i <= (x2 - x1); i++)
		cout << ch;
}
void drawCol(int x, int y1, int y2, char ch)
{
	int y = y1;
	while (y <= y2)
	{
		SetPos(x, y);
		cout << ch;
		y++;
	}
}
void drawFrame(COORD a, COORD b, char row, char col)
{
	drawRow(a.Y, a.X + 1, b.X - 1, row);
	drawRow(b.Y, a.X + 1, b.X - 1, row);
	drawCol(a.X, a.Y + 1, b.Y - 1, col);
	drawCol(b.X, a.Y + 1, b.Y - 1, col);
}
void drawFrame(int x1, int y1, int x2, int y2, char row, char col)
{
	COORD a = { (short)x1, (short)y1 };
	COORD b = { (short)x2, (short)y2 };
	drawFrame(a, b, row, col);
}
void drawFrame(Frame f, char row, char col)
{
	drawFrame(f.position[0], f.position[1], row, col);
}

void clearRect(Frame f)
{
	COORD lt = f.position[0];
	COORD rb = f.position[1];
	int y_start = lt.Y;
	int y_end = rb.Y;
	if(y_start <= 0) y_start = 1;
	if(y_end >= 24) y_end = 23;
	int x1 = lt.X;
	int x2 = rb.X;
	if(x1 <= 0) x1 = 1;
	if(x2 >= 48) x2 = 47;
	for (int y = y_start; y <= y_end; y++)
	{
		drawRow(y, x1, x2, ' ');
	}
}
void clearOldRect(Frame f)
{
	COORD lt = f.oldPos[0];
	COORD rb = f.oldPos[1];
	int y_start = lt.Y;
	int y_end = rb.Y;
	if(y_start <= 0) y_start = 1;
	if(y_end >= 24) y_end = 23;
	int x1 = lt.X;
	int x2 = rb.X;
	if(x1 <= 0) x1 = 1;
	if(x2 >= 48) x2 = 47;
	for (int y = y_start; y <= y_end; y++)
	{
		drawRow(y, x1, x2, ' ');
	}
}
void savePosToOld(Frame &f)
{
	f.oldPos[0] = f.position[0];
	f.oldPos[1] = f.position[1];
}

void drawPlayingUI(bool isEndless)
{
	drawFrame(0, 0, 48, 24, '=', '|');
	drawFrame(49, 0, 79, 4, '-', '|');
	drawFrame(49, 4, 79, 9, '-', '|');
	drawFrame(49, 9, 79, 20, '-', '|');
	drawFrame(49, 20, 79, 24, '-', '|');
	SetPos(52, 6);cout << "得分:";
	if(!isEndless)
	{
		SetPos(52, 7);cout << "称号:";
		SetPos(52, 8);cout << "下级需要:";
	}
	SetPos(52,9);cout << "大招(F):";
	SetPos(52, 11);cout << "操作方式:";
	SetPos(52, 12);cout << "  ←→↑↓ 战机移动";
	SetPos(52, 13);cout << "  k 发射子弹";
	SetPos(52, 14);cout << "  f 释放大招";
	SetPos(52, 15);cout << "  p 暂停游戏";
	SetPos(52, 16);cout << "  e 退出游戏";
	SetPos(52, 18);cout << "请切换英文输入法";
	SetPos(52, 19);cout << "否则方向键可能失效";
}
int random(int L, int R)
{
	if (L > R) swap(L, R);
	return L + rand() % (R - L + 1);
}
COORD random(COORD a, COORD b)
{
	int x = random(a.X, b.X);
	int y = random(a.Y, b.Y);
	COORD c = { (short)x, (short)y };
	return c;
}
bool judgeCoordInFrame(Frame frame, COORD spot)
{
	COORD lt = frame.position[0];
	COORD rb = frame.position[1];
	if (spot.X >= lt.X && spot.X <= rb.X && spot.Y >= lt.Y && spot.Y <= rb.Y)
		return true;
	return false;
}

void SpawnEnemy(Frame &e)
{
	COORD a = { (short)1,(short)1 };
	COORD b = { (short)44,(short)3 };
	e.position[0] = random(a, b);
	e.position[1].X = (short)(e.position[0].X + 3);
	e.position[1].Y = (short)(e.position[0].Y + 2);
	savePosToOld(e);
	int r = rand()%10;
	if(r < 7)
	{
		e.type = ENEMY_NORMAL;
		e.hp = 1;
	}
	else if(r < 8)
	{
		e.type = ENEMY_FAST;
		e.hp = 1;
	}
	else if(r < 9)
	{
		e.type = ENEMY_HEAVY;
		e.hp = 3;
	}
	else
	{
		e.type = ENEMY_SHOOT;
		e.hp = 1;
	}
	e.explodeTimer = 0;
}
void SpawnPlusEnemy(Frame &e, int spawnX, int spawnY)
{
	e.position[0].X = (short)spawnX;
	e.position[0].Y = (short)spawnY;
	e.position[1].X = (short)(spawnX+1);
	e.position[1].Y = (short)(spawnY+1);
	savePosToOld(e);
	e.type = ENEMY_PLUS;
	e.hp = 1;
	e.explodeTimer = 0;
}

void DrawEnemyByType(Frame f)
{
	if(f.hp <=0 && f.explodeTimer <=0) return;
	if(f.explodeTimer>0)
	{
		COORD lt = f.position[0];
		SetPos(lt.X,lt.Y);cout<<"*+*";
		SetPos(lt.X,lt.Y+1);cout<<"+*+";
		SetPos(lt.X,lt.Y+2);cout<<"*+*";
		return;
	}
	if(f.type == ENEMY_NORMAL) drawFrame(f,'-','|');
	else if(f.type == ENEMY_FAST) drawFrame(f,'~','|');
	else if(f.type == ENEMY_HEAVY) drawFrame(f,'#','|');
	else if(f.type == ENEMY_SHOOT) drawFrame(f,'*','|');
	else if(f.type == ENEMY_PLUS)
	{
		SetPos(f.position[0].X,f.position[0].Y); cout<<"+";
	}
}

void DrawHelpText()
{
	StartHelpBGM();
	string helpLines[] = {
		"【玩法说明】",
		"方向键 ←→↑↓ 移动你的飞机",
		"k发射普通子弹,f释放散射大招",
		"p暂停游戏,e退出游戏",
		"敌机识别:(-)普通 (~)快速 (#)重甲 (*)射击敌机",
		"普通5分;快速5分;重甲需打3次,15分;射击敌机击杀10分",
		"(*)射击敌机每1.5秒释放小型+高速敌机作为炮弹!",
		"普通模式:700分出现BOSS;无尽模式300分通关下一关,每3关BOSS",
		"BOSS【5秒一次】向下发射一排+炮弹;【2秒一次】投放7架普通敌机",
		"发射炮弹、投放敌机屏幕出现临时提示,提示会自动消失",
		"冷酷模式:敌机速度1.5倍,击杀得分 ×2",
		"大招F:固定10秒冷却",
		"无尽模式无称号,目标300分通关本关",
		"击败BOSS直接通关,被敌机本体命中直接坠毁!"
	};
	system("cls");
	for(int i=0;i<14;i++)
	{
		SetPos(4,2+i);
		for(int c=0;c<helpLines[i].size();c++)
		{
			cout<<helpLines[i][c];
			Sleep(30);
		}
	}
	SetPos(22,17);
	cout<<"按任意键返回主菜单";
	_getch();
}

//返回值:1简单普通 2冷酷普通 3简单无尽 4冷酷无尽
int drawMenu()
{
	system("cls");
	SetPos(32, 1);
	cout << "飞 机 大 战";
	SetPos(44,2);cout<<"v3.1";
	SetPos(22, 3);cout << "=============================================";
	SetPos(24, 4);cout << "【重要提示】运行前请切换至英文输入法!";
	SetPos(22, 5);cout << "=============================================";
	drawRow(7, 0, 79, '-');
	drawRow(13, 0, 79, '-');
	SetPos(28, 8);cout << "↑ / ↓ 切换选项, k 确认";
	SetPos(15, 10);cout << "1. 简单普通模式";
	SetPos(15, 12);cout << "2. 冷酷普通模式(速度*1.5,得分*2)";
	SetPos(15, 14);cout << "3. 简单无尽模式(300分下一关)";
	SetPos(15, 16);cout << "4. 冷酷无尽模式(速度*1.5,得分*2)";
	SetPos(15, 18);cout << "5. 查看玩法说明";
	drawRow(20, 0, 79, '-');
	drawRow(22, 0, 79, '-');
	SetPos(24, 21);cout << "制作:JohnShu";
	int j = 10;
	SetPos(12, j);cout << ">>";
	while (1)
	{
		if (_kbhit())
		{
			int key = _getch();
			if (key == 224)
			{
				int arrow = _getch();
				switch (arrow)
				{
				case 72:
					if(j>10){PlaySelectSound();SetPos(12,j);cout<<" ";j-=2;SetPos(12,j);cout<<">>";}break;
				case 80:
					if(j<18){PlaySelectSound();SetPos(12,j);cout<<" ";j+=2;SetPos(12,j);cout<<">>";}break;
				}
			}
			else if (key == 'k')
			{
				if(j ==10) return 1;
				else if(j ==12) return 2;
				else if(j ==14) return 3;
				else if(j ==16) return 4;
				else if(j ==18){DrawHelpText();return 5;}
			}
		}
	}
}

class Game
{
public:
	COORD position[10];
	COORD bullet[50];
	COORD bulletOldPos[50];
	Frame enemy[20];
	int score;
	int oldScore;
	int speedInterval;
	const int MIN_INTERVAL = 20;
	int shootCd;
	const int CD_MAX = 6;
	string title;
	bool hardMode;
	bool isEndlessMode;
	int level;
	int enemyShootTimer[8];
	
	int ultCooldownTick;
	const int ULT_FIXED_TICK = 1250;
	int lastMoveKey;
	void FireUlt();
	
	Frame boss;
	bool bossExist;
	bool bossWarningDone;
	bool isWinGame;
	bool nextLevelFlag;
	int bossHp;
	int bossTimerShoot;
	int bossTimerSpawnEnemy;
	int bossMoveDir;
	
	char msgBuf[40];
	int msgTimer;
	
	Game();
	void initPlane();
	void initBullet();
	void initEnemy();
	void planeMove(int keyCode);
	void bulletMove();
	void enemyMove();
	void UpdatePlusBullets();
	void CheckShootEnemyFire();
	void ShowBossWarning();
	void drawPlane();
	void drawPlaneToNull();
	void drawBullet();
	void drawBulletToNull();
	void drawEnemyAll();
	void eraseEnemyAll();
	void drawThisBulletToNull(COORD);
	void drawThisEnemyToNull(Frame);
	void drawExplosion(Frame &f);
	void UpdateExplosion();
	void DrawBoss();
	void ClearBoss();
	void Pause();
	void Playing();
	void judgePlane();
	void judgeEnemy();
	void Shoot();
	void GameOver();
	void GameWin();
	void NextEndlessLevel();
	void printScore();
	void printUltStatus();
	string getTitleByScore(int s);
	void getNextInfo(int s, int& need, string& nextT);
	void SetTempMsg(const char* text);
	void UpdateTempMsg();
};

void Game::FireUlt()
{
	if(ultCooldownTick > 0) return;
	PlayUltSound();
	int startX = position[5].X - 24;
	for(int d = 0; d < 50; d++)
	{
		int bx = startX + d;
		if(bx < 1 || bx > 47) continue;
		for(int i = 0; i < 50; i++)
		{
			if(bullet[i].Y == 30)
			{
				bullet[i].X = (short)bx;
				bullet[i].Y = (short)(position[5].Y - 1);
				bulletOldPos[i] = bullet[i];
				break;
			}
		}
	}
	ultCooldownTick = ULT_FIXED_TICK;
}

Game::Game()
{
	initPlane();
	initBullet();
	initEnemy();
	score = 0;
	oldScore = -1;
	speedInterval = 35;
	shootCd = 0;
	title = "实习飞行员";
	hardMode = false;
	isEndlessMode = false;
	level = 1;
	for(int i = 0; i < 8; i++) enemyShootTimer[i] = 0;
	ultCooldownTick = 0;
	lastMoveKey = -1;
	
	bossExist = false;
	bossWarningDone = false;
	isWinGame = false;
	nextLevelFlag = false;
	bossHp = 100;
	bossTimerShoot = 0;
	bossTimerSpawnEnemy = 0;
	bossMoveDir = 1;
	savePosToOld(boss);
	
	msgBuf[0] = 0;
	msgTimer = 0;
}

void Game::SetTempMsg(const char* text)
{
	strncpy_s(msgBuf, text, sizeof(msgBuf)-1);
	msgTimer = 25;
}
void Game::UpdateTempMsg()
{
	if(msgTimer >0)
	{
		SetPos(10, 1);
		cout << msgBuf;
		msgTimer--;
		if(msgTimer <=0)
		{
			drawRow(1,10,40,' ');
			msgBuf[0]=0;
		}
	}
}

string Game::getTitleByScore(int s)
{
	if(isEndlessMode) return "";
	if (s < 120) return "实习飞行员";
	else if (s < 360) return "初级飞行员";
	else if (s < 480) return "中级飞行员";
	else if (s < 700) return "高级飞行员";
	else return "王牌飞行员";
}
void Game::getNextInfo(int s, int& need, string& nextT)
{
	if(isEndlessMode){ need=0; nextT=""; return; }
	if (s < 120) { need = 120 - s; nextT = "初级飞行员"; }
	else if (s < 360) { need = 360 - s; nextT = "中级飞行员"; }
	else if (s < 480) { need = 480 - s; nextT = "高级飞行员"; }
	else if (s < 700) { need = 700 - s; nextT = "王牌飞行员"; }
	else { need = 0; nextT = "已满级"; }
}
void Game::initPlane()
{
	COORD centren = { (short)39, (short)22 };
	position[0].X = position[5].X = position[7].X = position[9].X = centren.X;
	position[1].X = (short)(centren.X - 2);
	position[2].X = position[6].X = (short)(centren.X - 1);
	position[3].X = position[8].X = (short)(centren.X + 1);
	position[4].X = (short)(centren.X + 2);
	for (int i = 0; i <= 4; i++) position[i].Y = centren.Y;
	position[5].Y = (short)(centren.Y - 1);
	for (int i = 6; i <= 8; i++) position[i].Y = (short)(centren.Y + 1);
	position[9].Y = (short)(centren.Y - 2);
}
void Game::drawPlane()
{
	for (int i = 0; i < 10; i++)
	{
		SetPos(position[i]);
		if (i == 5) cout << "|";
		else cout << "O";
	}
}
void Game::drawPlaneToNull()
{
	for (int i = 0; i < 10; i++)
	{
		SetPos(position[i]);
		cout << " ";
	}
}
void Game::initBullet()
{
	for (int i = 0; i < 50; i++)
	{
		bullet[i].Y = (short)30;
		bulletOldPos[i].Y = (short)30;
	}
}

void Game::drawBullet()
{
	for (int i = 0; i < 50; i++)
	{
		if (bullet[i].Y != 30)
		{
			if (bulletOldPos[i].Y != 30)
			{
				SetPos(bulletOldPos[i]);
				cout << " ";
			}
			SetPos(bullet[i]);
			cout << "^";
			bulletOldPos[i] = bullet[i];
		}
		else
		{
			if (bulletOldPos[i].Y != 30)
			{
				SetPos(bulletOldPos[i]);
				cout << " ";
			}
			bulletOldPos[i].Y = (short)30;
		}
	}
}

void Game::drawBulletToNull()
{
	for (int i = 0; i < 50; i++)
	{
		if (bullet[i].Y != 30)
		{
			SetPos(bullet[i]);
			cout << " ";
		}
		bullet[i].Y = (short)30;
		if (bulletOldPos[i].Y != 30)
		{
			SetPos(bulletOldPos[i]);
			cout << " ";
		}
		bulletOldPos[i].Y = (short)30;
	}
}
void Game::initEnemy()
{
	for(int i = 0; i < 8; i++)
		SpawnEnemy(enemy[i]);
	for(int i = 8; i < 20; i++){
		enemy[i].hp = 0;
		enemy[i].type = -1;
		enemy[i].explodeTimer =0;
		savePosToOld(enemy[i]);
	}
}
void Game::drawEnemyAll()
{
	for (int i = 0; i < 20; i++)
	{
		if(enemy[i].hp >0 || enemy[i].explodeTimer>0) DrawEnemyByType(enemy[i]);
	}
}
void Game::eraseEnemyAll()
{
	for (int i = 0; i < 20; i++)
	{
		if(enemy[i].hp >0 || enemy[i].explodeTimer>0)
		{
			clearRect(enemy[i]);
		}
	}
}
void Game::drawThisEnemyToNull(Frame f)
{
	clearRect(f);
}
void Game::drawExplosion(Frame &f)
{
	PlayExplodeSound();
	f.hp = 0;
	f.explodeTimer = 10;
}
void Game::UpdateExplosion()
{
	for(int i=0;i<20;i++)
	{
		if(enemy[i].explodeTimer>0)
		{
			enemy[i].explodeTimer--;
			if(enemy[i].explodeTimer <=0)
			{
				clearRect(enemy[i]);
				enemy[i].type = -1;
			}
		}
	}
}

void Game::DrawBoss()
{
	if(!bossExist) return;
	drawFrame(boss.position[0],boss.position[1],'@','#');
}
void Game::ClearBoss()
{
	clearRect(boss);
}

void Game::ShowBossWarning()
{
	PlayBossWarning();
	for(int t = 0; t < 3; t++)
	{
		SetPos(28, 10);
		cout << "!!!! BOSS 来袭 !!!!";
		Sleep(500);
		SetPos(28, 10);
		cout << "                    ";
		Sleep(500);
	}
	SetPos(28, 10);
	cout << "!!!! BOSS 来袭 !!!!";
	Sleep(1000);
	drawRow(10,28,46,' ');
}

void Game::CheckShootEnemyFire()
{
	for(int i = 0; i < 8; i++)
	{
		if(enemy[i].hp <= 0) continue;
		if(enemy[i].type != ENEMY_SHOOT) continue;
		enemyShootTimer[i]++;
		if(enemyShootTimer[i] >= 63)
		{
			enemyShootTimer[i] = 0;
			for(int slot = 8; slot < 20; slot++)
			{
				if(enemy[slot].hp <= 0 && enemy[slot].explodeTimer <=0)
				{
					SpawnPlusEnemy(enemy[slot], enemy[i].position[0].X + 1, enemy[i].position[1].Y + 1);
					enemy[slot].hp = 1;
					break;
				}
			}
		}
	}
}

void Game::UpdatePlusBullets()
{
	for(int i = 8; i < 20; i++)
	{
		if(enemy[i].hp >0 && enemy[i].type == ENEMY_PLUS)
		{
			clearOldRect(enemy[i]);
			enemy[i].position[0].Y +=2;
			enemy[i].position[1].Y +=2;
			savePosToOld(enemy[i]);
			if(enemy[i].position[1].Y >=23)
			{
				clearRect(enemy[i]);
				enemy[i].hp =0;
				enemy[i].type =-1;
			}
		}
	}
}

void Game::Pause()
{
	drawRow(2, 61, 79, ' ');
	SetPos(61, 2);
	cout << "暂停中...按p继续";
	int c = _getch();
	while (c != 'p') c = _getch();
	drawRow(2, 61, 79, ' ');
}
void Game::planeMove(int keyCode)
{
	bool moved = false;
	if (keyCode == 75)
		if (position[1].X > 1)
		{
			for (int i = 0; i < 10; i++) position[i].X = (short)(position[i].X - 1);
			moved = true;
		}
	if (keyCode == 80)
		if (position[7].Y < 23)
		{
			for (int i = 0; i < 10; i++) position[i].Y = (short)(position[i].Y + 1);
			moved = true;
		}
	if (keyCode == 77)
		if (position[4].X < 47)
		{
			for (int i = 0; i < 10; i++) position[i].X = (short)(position[i].X + 1);
			moved = true;
		}
	if (keyCode == 72)
		if (position[9].Y > 3)
		{
			for (int i = 0; i < 10; i++) position[i].Y = (short)(position[i].Y - 1);
			moved = true;
		}
	if(moved && lastMoveKey != keyCode)
	{
		PlayPlaneMoveSound();
		lastMoveKey = keyCode;
	}
	else if(!moved)
	{
		lastMoveKey = -1;
	}
}
void Game::bulletMove()
{
	for (int i = 0; i < 50; i++)
	{
		if (bullet[i].Y != 30)
		{
			bullet[i].Y = (short)(bullet[i].Y - 1);
			if (bullet[i].Y <= 1)
			{
				bullet[i].Y = (short)30;
			}
		}
	}
}
void Game::enemyMove()
{
	for (int i = 0; i < 8; i++)
	{
		if(enemy[i].hp <= 0) continue;
		clearOldRect(enemy[i]);
		int step = 1;
		for(int s = 0; s < step; s++)
		{
			enemy[i].position[0].Y++;
			enemy[i].position[1].Y++;
			if (enemy[i].position[1].Y >= 23)
			{
				SpawnEnemy(enemy[i]);
				enemyShootTimer[i] = 0;
				break;
			}
		}
		savePosToOld(enemy[i]);
	}
	
	if(bossExist)
	{
		clearOldRect(boss);
		int bLeft = boss.position[0].X;
		int bRight = boss.position[1].X;
		if(bLeft <= 2) bossMoveDir = 1;
		if(bRight >= 44) bossMoveDir = -1;
		boss.position[0].X += (short)bossMoveDir;
		boss.position[1].X += (short)bossMoveDir;
		savePosToOld(boss);
	}
}

void Game::NextEndlessLevel()
{
	score = 0;
	level++;
	if(speedInterval>22)speedInterval--;
	initEnemy();
	initBullet();
	bossExist = false;
	bossWarningDone = false;
	bossHp = 100;
	bossTimerShoot =0;
	bossTimerSpawnEnemy =0;
	bossMoveDir =1;
	nextLevelFlag = false;
	system("cls");
	drawPlayingUI(true);
}

void Game::judgePlane()
{
	for (int i = 0; i < 20; i++)
	{
		if(enemy[i].hp <= 0) continue;
		for (int j = 0; j < 10; j++)
			if (judgeCoordInFrame(enemy[i], position[j]))
			{
				drawRow(1, 62, 70, ' ');
				SetPos(62, 1);
				cout << "坠毁";
				drawFrame(enemy[i], '+', '+');
				PlayCrashSound();
				Sleep(1000);
				GameOver();
				return;
			}
	}
	if(bossExist)
	{
		for(int j = 0; j < 10; j++)
		{
			if(judgeCoordInFrame(boss, position[j]))
			{
				drawRow(1, 62, 70, ' ');
				SetPos(62, 1);cout << "坠毁";
				PlayCrashSound();Sleep(1000);
				GameOver();return;
			}
		}
	}
}

void Game::drawThisBulletToNull(COORD c)
{
	SetPos(c);
	cout << " ";
}
void Game::judgeEnemy()
{
	for (int i = 0; i < 20; i++)
	{
		if(enemy[i].hp <= 0) continue;
		for (int j = 0; j < 50; j++)
		{
			if (judgeCoordInFrame(enemy[i], bullet[j]))
			{
				enemy[i].hp--;
				drawThisBulletToNull(bullet[j]);
				bullet[j].Y = (short)30;
				bulletOldPos[j].Y = (short)30;
				
				if(enemy[i].hp > 0)
				{
					PlayHitSound();
					return;
				}
				clearRect(enemy[i]);
				int addScore;
				if(enemy[i].type == ENEMY_SHOOT) addScore = 10;
				else if(enemy[i].type == ENEMY_HEAVY) addScore = 15;
				else if(enemy[i].type == ENEMY_PLUS) addScore = 10;
				else addScore = 5;
				if(hardMode) addScore *= 2;
				
				score += addScore;
				drawExplosion(enemy[i]);
				
				if(i < 8)
				{
					SpawnEnemy(enemy[i]);
					enemyShootTimer[i] = 0;
				}
				printScore();
				
				if(isEndlessMode && score >=300)
				{
					nextLevelFlag = true;
				}
				return;
			}
		}
	}
	if(bossExist)
	{
		for(int j = 0; j < 50; j++)
		{
			if(bullet[j].Y == 30) continue;
			if(judgeCoordInFrame(boss, bullet[j]))
			{
				bossHp--;
				drawThisBulletToNull(bullet[j]);
				bullet[j].Y = 30;
				bulletOldPos[j].Y = (short)30;
				PlayHitSound();
				if(bossHp <= 0)
				{
					ClearBoss();
					bossExist = false;
					if(!isEndlessMode)
					{
						isWinGame = true;
					}
				}
			}
		}
	}
}
void Game::Shoot()
{
	if (shootCd > 0) return;
	for (int i = 0; i < 50; i++)
		if (bullet[i].Y == 30)
		{
			bullet[i].X = position[5].X;
			bullet[i].Y = (short)(position[5].Y - 1);
			bulletOldPos[i] = bullet[i];
			shootCd = CD_MAX;
			break;
		}
	
}

void Game::printUltStatus()
{
	drawRow(9,60,78,' ');
	SetPos(60,9);
	if(ultCooldownTick > 0)
	{
		int sec = ultCooldownTick / 125;
		cout<<sec<<"s冷却";
	}
	else
	{
		cout<<"【就绪】";
	}
}

void Game::printScore()
{
	if(score == oldScore) return;
	oldScore = score;
	int nextNeed = 0;
	string nextTitle = "";
	title = getTitleByScore(score);
	getNextInfo(score, nextNeed, nextTitle);
	
	if(!isEndlessMode)
	{
		int base = speedInterval;
		if (score >= 120 && base > MIN_INTERVAL) base -=1;
		if (score >= 360 && base > MIN_INTERVAL) base -=1;
		if (score >= 480 && base > MIN_INTERVAL) base -=1;
		if (score >= 700 && base > MIN_INTERVAL) base -=1;
		if(base < MIN_INTERVAL) base = MIN_INTERVAL;
		speedInterval = base;
	}
	
	drawRow(6, 60, 78, ' ');
	SetPos(60, 6); cout << score;
	if(!isEndlessMode)
	{
		drawRow(7, 60, 78, ' ');
		SetPos(60, 7); cout << title;
		drawRow(8, 60, 78, ' ');
		SetPos(60, 8);
		if(nextNeed>0) cout << nextNeed << "分->" << nextTitle;
		else cout << nextTitle;
	}
	else
	{
		drawRow(7,60,78,' ');
		SetPos(60,7);cout<<"第"<<level<<"关";
		drawRow(8,60,78,' ');
		SetPos(60,8);cout<<"目标:300分";
	}
	printUltStatus();
}

void Game::GameWin()
{
	PlayWinSound();
	StopAllSound();
	system("cls");
	drawRow(6, 10, 65, '=');
	drawRow(14, 10, 65, '=');
	drawCol(10, 7, 13, '|');
	drawCol(65, 7, 13, '|');
	SetPos(28, 8);  cout << "You win !";
	SetPos(24, 10); cout << "击落敌机:" << score / 5 << " 架";
	SetPos(24, 11); cout << "得  分:" << score;
	if(!isEndlessMode)
		SetPos(24, 12); cout << "获得称号:" << getTitleByScore(score);
	Sleep(1500);
	system("cls");
	drawRow(4, 8, 67, '=');
	drawRow(18, 8, 67, '=');
	drawCol(8, 5, 17, '|');
	drawCol(67, 5, 17, '|');
	SetPos(26, 6);  cout << "击落敌机:" << score / 5 << " 架";
	SetPos(26, 8);  cout << "得  分:" << score;
	if(!isEndlessMode)
		SetPos(26, 10); cout << "获得称号:" << getTitleByScore(score);
	SetPos(26, 12); cout << "恭喜通关全部内容!";
	SetPos(10, 20);
	cout << "继续? 是(y) | 否(n)";
	as_win:
	int x = _getch();
	if (x == 'n') exit(0);
	else if (x == 'y')
	{
		system("cls");
		Game newGame;
		int sel;
		do
		{
			sel = drawMenu();
		}while(sel == 5);
		if(sel == 2 || sel ==4)
		{
			newGame.hardMode = true;
			newGame.speedInterval = 23;
		}
		else
		{
			newGame.hardMode = false;
			newGame.speedInterval = 35;
		}
		if(sel ==3 || sel ==4) newGame.isEndlessMode = true;
		
		system("cls");
		drawPlayingUI(newGame.isEndlessMode);
		newGame.Playing();
	}
	else goto as_win;
}

void Game::Playing()
{
	//进入对局:关闭菜单BGM,开启战斗BGM
	StopAllSound();
	StartBattleBGM();
	
	drawEnemyAll();
	DrawBoss();
	drawPlane();
	printScore();
	int flag_bullet = 0;
	int flag_enemy = 0;
	const int FRAME_SLEEP = 8;
	while (1)
	{
		Sleep(FRAME_SLEEP);
		UpdateTempMsg();
		UpdateExplosion();
		
		if(bossExist)
		{
			bossTimerShoot++;
			bossTimerSpawnEnemy++;
			if(bossTimerShoot >= 625)
			{
				bossTimerShoot = 0;
				SetTempMsg("BOSS:发射炮弹!");
				int totalW = boss.position[1].X - boss.position[0].X;
				for(int b = 0; b < 25; b++)
				{
					int slot = -1;
					for(int s = 8; s < 20; s++)
					{
						if(enemy[s].hp <=0 && enemy[s].explodeTimer <=0)
						{
							slot = s;
							break;
						}
					}
					if(slot == -1) break;
					int spawnX = boss.position[0].X + (b * totalW)/24;
					if(spawnX <1) spawnX=1;
					if(spawnX>47) spawnX=47;
					SpawnPlusEnemy(enemy[slot], spawnX, boss.position[1].Y + 1);
					enemy[slot].hp =1;
				}
			}
			if(bossTimerSpawnEnemy >= 250)
			{
				bossTimerSpawnEnemy = 0;
				SetTempMsg("BOSS:投放敌机!");
				int cnt = 0;
				for(int k = 0; k < 8;k++)
				{
					if(enemy[k].hp <= 0 && cnt <7)
					{
						SpawnEnemy(enemy[k]);
						cnt++;
					}
				}
			}
		}
		else
		{
			if(!isEndlessMode)
			{
				if(score >= 700 && !bossWarningDone)
				{
					bossWarningDone = true;
					ShowBossWarning();
					bossExist = true;
					bossHp = 100;
					bossTimerShoot = 0;
					bossTimerSpawnEnemy = 0;
					bossMoveDir = 1;
					boss.position[0].X = 10;
					boss.position[0].Y = 2;
					boss.position[1].X = 30;
					boss.position[1].Y = 6;
					savePosToOld(boss);
					PlayBossAppear();
				}
			}
			else
			{
				if( (level%3 ==0) && !bossWarningDone )
				{
					bossWarningDone = true;
					ShowBossWarning();
					bossExist = true;
					bossHp = 100;
					bossTimerShoot = 0;
					bossTimerSpawnEnemy = 0;
					bossMoveDir = 1;
					boss.position[0].X = 10;
					boss.position[0].Y = 2;
					boss.position[1].X = 30;
					boss.position[1].Y = 6;
					savePosToOld(boss);
					PlayBossAppear();
				}
			}
		}
		
		CheckShootEnemyFire();
		UpdatePlusBullets();
		
		if(isWinGame)
		{
			GameWin();
			break;
		}
		if(nextLevelFlag)
		{
			PlayWinSound();
			StopAllSound();
			system("cls");
			SetPos(22,10);cout<<"=====You Win! 进入第"<<(level+1)<<"关=====";
			Sleep(1200);
			NextEndlessLevel();
			StartBattleBGM();
			drawEnemyAll();
			DrawBoss();
			drawPlane();
			printScore();
		}
		
		if(ultCooldownTick > 0) ultCooldownTick--;
		
		if (shootCd > 0) shootCd--;
		if (_kbhit())
		{
			int key = _getch();
			if (key == 224)
			{
				int arrow = _getch();
				drawPlaneToNull();
				planeMove(arrow);
				drawPlane();
				judgePlane();
			}
			else if (key == 'p') Pause();
			else if (key == 'k') Shoot();
			else if(key == 'f') FireUlt();
			else if (key == 'e')
			{
				GameOver();
				break;
			}
		}
		
		if (flag_bullet == 0)
		{
			bulletMove();
			drawBullet();
			judgeEnemy();
			judgePlane();
		}
		flag_bullet = (flag_bullet + 1) % 7;
		
		if (flag_enemy == 0)
		{
			enemyMove();
		}
		drawEnemyAll();
		if(bossExist) DrawBoss();
		drawFrame(0, 0, 48, 24, '=', '|');
		judgePlane();
		
		flag_enemy = (flag_enemy + 1) % speedInterval;
		printUltStatus();
	}
}

void Game::GameOver()
{
	PlayCrashSound();
	StopAllSound();
	system("cls");
	drawRow(6, 10, 65, '=');
	drawRow(12, 10, 65, '=');
	drawCol(10, 7, 11, '|');
	drawCol(65, 7, 11, '|');
	SetPos(30, 8); cout << "Game Over!";
	Sleep(1000);
	system("cls");
	drawRow(4, 8, 67, '=');
	drawRow(19, 8, 67, '=');
	drawCol(8, 5, 18, '|');
	drawCol(67, 5, 18, '|');
	SetPos(26, 6);  cout << "击落敌机:" << score / 5 << " 架";
	SetPos(26, 8);  cout << "得  分:" << score;
	
	//修复无尽模式结算:不显示称号,改为显示坚持到第几关
	if(isEndlessMode)
	{
		SetPos(26, 10); cout << "你坚持到了:第" << level << "关";
	}
	else
	{
		SetPos(26, 10); cout << "获得称号:" << getTitleByScore(score);
		SetPos(10, 13); cout << "0~119分   实习飞行员";
		SetPos(10, 14); cout << "120~359分 初级飞行员";
		SetPos(10, 15); cout << "360~479分 中级飞行员";
		SetPos(10, 16); cout << "480~699分 高级飞行员";
		SetPos(10, 17); cout << "≥700分    王牌飞行员";
	}
	
	SetPos(10, 21);
	cout << "继续? 是(y) | 否(n)";
	as_over:
	int x = _getch();
	if (x == 'n') exit(0);
	else if (x == 'y')
	{
		system("cls");
		Game newGame;
		int sel;
		do
		{
			sel = drawMenu();
		}while(sel == 5);
		if(sel ==2 || sel ==4)
		{
			newGame.hardMode = true;
			newGame.speedInterval = 23;
		}
		else
		{
			newGame.hardMode = false;
			newGame.speedInterval = 35;
		}
		if(sel ==3 || sel ==4) newGame.isEndlessMode = true;
		
		system("cls");
		drawPlayingUI(newGame.isEndlessMode);
		newGame.Playing();
	}
	else goto as_over;
}

int main()
{
	DisableQuickEdit();
	SetConsoleTitleW(L"飞机大战 v3.1");
	srand((unsigned)time(NULL));
	HideCursor();
	
	system("cls");
	
	for(int y = 0; y <= 8; y++)
	{
		system("cls");
		SetPos(30, y);
		cout << "================";
		SetPos(33, y + 1);
		cout << "飞机大战";
		SetPos(38, y + 2);
		cout << "v3.1";
		SetPos(30, y + 3);
		cout << "================";
		if(y % 3 == 2) PlayTitleEnterSound();
		Sleep(90);
	}
	
	SetPos(28, 13);
	cout << "制作:JohnShu";
	SetPos(24, 15);
	cout << "【原创游戏,假冒必究】";
	Sleep(2200);
	
	StartHelpBGM();
	for(int i=0;i<=100;i++)
	{
		system("cls");
		cout<<"--------------------------------------------"<<endl;
		cout<<"  游戏:飞机大战v3.1        ------------------------------"<<endl;
		cout<<"  【敌机】普通|快速|重甲|射击敌机|BOSS"<<endl;
		cout<<"  【操作】方向键移动,k射击,f大招,p暂停,e退出"<<endl;
		cout<<"  【提示】请务必切换英文输入法,防止按键失效!"<<endl;
		cout<<"  正在加载:"<<i<<'%'<<"-----------------------------"<<endl;
		cout<<"--------------------------------------------"<<endl;
		Sleep(100);
	}
	
	system("cls");
	cout<<"--------------------------------------------"<<endl;
	cout<<"        飞机大战 v3.1"<<endl;
	cout<<"        是否查看玩法引导?"<<endl;
	cout<<"        按【y】查看,其他键跳过"<<endl;
	cout<<"--------------------------------------------"<<endl;
	int ch = _getch();
	if(ch == 'y' || ch == 'Y')
	{
		DrawHelpText();
	}
	StopAllSound();
	
	system("cls");
	
	Game game;
	int sel;
	do
	{
		sel = drawMenu();
	}while(sel == 5);
	
	if(sel == 2 || sel ==4)
	{
		game.hardMode = true;
		game.speedInterval = 23;
	}
	else
	{
		game.hardMode = false;
		game.speedInterval = 35;
	}
	if(sel ==3 || sel ==4)
	{
		game.isEndlessMode = true;
	}
	
	system("cls");
	drawPlayingUI(game.isEndlessMode);
	game.Playing();
	return 0;
}

✈️飞机大战v3.1_静音版代码

C++
#include<iostream>
#include<windows.h>
#include<mmsystem.h>
#include<conio.h>
#include<time.h>
#include<string>
using namespace std;

#define ENEMY_NORMAL 0
#define ENEMY_FAST   1
#define ENEMY_HEAVY  2
#define ENEMY_SHOOT  3
#define ENEMY_PLUS   4

typedef struct Frame
{
	COORD position[2];
	COORD oldPos[2];
	int flag;
	int type;
	int hp;
	int explodeTimer;
}Frame;

void DisableQuickEdit()
{
	HANDLE hConsole = GetStdHandle(STD_INPUT_HANDLE);
	DWORD mode;
	GetConsoleMode(hConsole, &mode);
	mode &= ~ENABLE_QUICK_EDIT_MODE;
	SetConsoleMode(hConsole, mode);
}

//静音版示例,全部音效函数改为空
void PlayTitleEnterSound(){}
void PlayUltSound(){}
void PlaySelectSound(){}
void PlayPlaneMoveSound(){}
void PlayExplodeSound(){}
void PlayCrashSound(){}
void PlayHitSound(){}
void PlayBossAppear(){}
void PlayBossWarning(){}
void PlayWinSound(){}
void StartHelpBGM(){}
void StartBattleBGM(){}
void StopAllSound(){}

void SetPos(COORD a)
{
	HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(out, a);
}
void SetPos(int i, int j)
{
	COORD pos = { (short)i, (short)j };
	SetPos(pos);
}
void HideCursor()
{
	CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void drawRow(int y, int x1, int x2, char ch)
{
	SetPos(x1, y);
	for (int i = 0; i <= (x2 - x1); i++)
		cout << ch;
}
void drawCol(int x, int y1, int y2, char ch)
{
	int y = y1;
	while (y <= y2)
	{
		SetPos(x, y);
		cout << ch;
		y++;
	}
}
void drawFrame(COORD a, COORD b, char row, char col)
{
	drawRow(a.Y, a.X + 1, b.X - 1, row);
	drawRow(b.Y, a.X + 1, b.X - 1, row);
	drawCol(a.X, a.Y + 1, b.Y - 1, col);
	drawCol(b.X, a.Y + 1, b.Y - 1, col);
}
void drawFrame(int x1, int y1, int x2, int y2, char row, char col)
{
	COORD a = { (short)x1, (short)y1 };
	COORD b = { (short)x2, (short)y2 };
	drawFrame(a, b, row, col);
}
void drawFrame(Frame f, char row, char col)
{
	drawFrame(f.position[0], f.position[1], row, col);
}

void clearRect(Frame f)
{
	COORD lt = f.position[0];
	COORD rb = f.position[1];
	int y_start = lt.Y;
	int y_end = rb.Y;
	if(y_start <= 0) y_start = 1;
	if(y_end >= 24) y_end = 23;
	int x1 = lt.X;
	int x2 = rb.X;
	if(x1 <= 0) x1 = 1;
	if(x2 >= 48) x2 = 47;
	for (int y = y_start; y <= y_end; y++)
	{
		drawRow(y, x1, x2, ' ');
	}
}
void clearOldRect(Frame f)
{
	COORD lt = f.oldPos[0];
	COORD rb = f.oldPos[1];
	int y_start = lt.Y;
	int y_end = rb.Y;
	if(y_start <= 0) y_start = 1;
	if(y_end >= 24) y_end = 23;
	int x1 = lt.X;
	int x2 = rb.X;
	if(x1 <= 0) x1 = 1;
	if(x2 >= 48) x2 = 47;
	for (int y = y_start; y <= y_end; y++)
	{
		drawRow(y, x1, x2, ' ');
	}
}
void savePosToOld(Frame &f)
{
	f.oldPos[0] = f.position[0];
	f.oldPos[1] = f.position[1];
}

void drawPlayingUI(bool isEndless)
{
	drawFrame(0, 0, 48, 24, '=', '|');
	drawFrame(49, 0, 79, 4, '-', '|');
	drawFrame(49, 4, 79, 9, '-', '|');
	drawFrame(49, 9, 79, 20, '-', '|');
	drawFrame(49, 20, 79, 24, '-', '|');
	SetPos(52, 6);cout << "得分:";
	if(!isEndless)
	{
		SetPos(52, 7);cout << "称号:";
		SetPos(52, 8);cout << "下级需要:";
	}
	SetPos(52,9);cout << "大招(F):";
	SetPos(52, 11);cout << "操作方式:";
	SetPos(52, 12);cout << "  ←→↑↓ 战机移动";
	SetPos(52, 13);cout << "  k 发射子弹";
	SetPos(52, 14);cout << "  f 释放大招";
	SetPos(52, 15);cout << "  p 暂停游戏";
	SetPos(52, 16);cout << "  e 退出游戏";
	SetPos(52, 18);cout << "请切换英文输入法";
	SetPos(52, 19);cout << "否则方向键可能失效";
}
int random(int L, int R)
{
	if (L > R) swap(L, R);
	return L + rand() % (R - L + 1);
}
COORD random(COORD a, COORD b)
{
	int x = random(a.X, b.X);
	int y = random(a.Y, b.Y);
	COORD c = { (short)x, (short)y };
	return c;
}
bool judgeCoordInFrame(Frame frame, COORD spot)
{
	COORD lt = frame.position[0];
	COORD rb = frame.position[1];
	if (spot.X >= lt.X && spot.X <= rb.X && spot.Y >= lt.Y && spot.Y <= rb.Y)
		return true;
	return false;
}

void SpawnEnemy(Frame &e)
{
	COORD a = { (short)1,(short)1 };
	COORD b = { (short)44,(short)3 };
	e.position[0] = random(a, b);
	e.position[1].X = (short)(e.position[0].X + 3);
	e.position[1].Y = (short)(e.position[0].Y + 2);
	savePosToOld(e);
	int r = rand()%10;
	if(r < 7)
	{
		e.type = ENEMY_NORMAL;
		e.hp = 1;
	}
	else if(r < 8)
	{
		e.type = ENEMY_FAST;
		e.hp = 1;
	}
	else if(r < 9)
	{
		e.type = ENEMY_HEAVY;
		e.hp = 3;
	}
	else
	{
		e.type = ENEMY_SHOOT;
		e.hp = 1;
	}
	e.explodeTimer = 0;
}
void SpawnPlusEnemy(Frame &e, int spawnX, int spawnY)
{
	e.position[0].X = (short)spawnX;
	e.position[0].Y = (short)spawnY;
	e.position[1].X = (short)(spawnX+1);
	e.position[1].Y = (short)(spawnY+1);
	savePosToOld(e);
	e.type = ENEMY_PLUS;
	e.hp = 1;
	e.explodeTimer = 0;
}

void DrawEnemyByType(Frame f)
{
	if(f.hp <=0 && f.explodeTimer <=0) return;
	if(f.explodeTimer>0)
	{
		COORD lt = f.position[0];
		SetPos(lt.X,lt.Y);cout<<"*+*";
		SetPos(lt.X,lt.Y+1);cout<<"+*+";
		SetPos(lt.X,lt.Y+2);cout<<"*+*";
		return;
	}
	if(f.type == ENEMY_NORMAL) drawFrame(f,'-','|');
	else if(f.type == ENEMY_FAST) drawFrame(f,'~','|');
	else if(f.type == ENEMY_HEAVY) drawFrame(f,'#','|');
	else if(f.type == ENEMY_SHOOT) drawFrame(f,'*','|');
	else if(f.type == ENEMY_PLUS)
	{
		SetPos(f.position[0].X,f.position[0].Y); cout<<"+";
	}
}

void DrawHelpText()
{
	StartHelpBGM();
	string helpLines[] = {
		"【玩法说明】",
		"方向键 ←→↑↓ 移动你的飞机",
		"k发射普通子弹,f释放散射大招",
		"p暂停游戏,e退出游戏",
		"敌机识别:(-)普通 (~)快速 (#)重甲 (*)射击敌机",
		"普通5分;快速5分;重甲需打3次,15分;射击敌机击杀10分",
		"(*)射击敌机每1.5秒释放小型+高速敌机作为炮弹!",
		"普通模式:700分出现BOSS;无尽模式300分通关下一关,每3关BOSS",
		"BOSS【5秒一次】向下发射一排+炮弹;【2秒一次】投放7架普通敌机",
		"发射炮弹、投放敌机屏幕出现临时提示,提示会自动消失",
		"冷酷模式:敌机速度1.5倍,击杀得分 ×2",
		"大招F:固定10秒冷却",
		"无尽模式无称号,目标300分通关本关",
		"击败BOSS直接通关,被敌机本体命中直接坠毁!"
	};
	system("cls");
	for(int i=0;i<14;i++)
	{
		SetPos(4,2+i);
		for(int c=0;c<helpLines[i].size();c++)
		{
			cout<<helpLines[i][c];
			Sleep(30);
		}
	}
	SetPos(22,17);
	cout<<"按任意键返回主菜单";
	_getch();
}

//返回值:1简单普通 2冷酷普通 3简单无尽 4冷酷无尽
int drawMenu()
{
	system("cls");
	SetPos(32, 1);
	cout << "飞 机 大 战";
	SetPos(44,2);cout<<"v3.1";
	SetPos(22, 3);cout << "=============================================";
	SetPos(24, 4);cout << "【重要提示】运行前请切换至英文输入法!";
	SetPos(22, 5);cout << "=============================================";
	drawRow(7, 0, 79, '-');
	drawRow(13, 0, 79, '-');
	SetPos(28, 8);cout << "↑ / ↓ 切换选项, k 确认";
	SetPos(15, 10);cout << "1. 简单普通模式";
	SetPos(15, 12);cout << "2. 冷酷普通模式(速度*1.5,得分*2)";
	SetPos(15, 14);cout << "3. 简单无尽模式(300分下一关)";
	SetPos(15, 16);cout << "4. 冷酷无尽模式(速度*1.5,得分*2)";
	SetPos(15, 18);cout << "5. 查看玩法说明";
	drawRow(20, 0, 79, '-');
	drawRow(22, 0, 79, '-');
	SetPos(24, 21);cout << "制作:JohnShu";
	int j = 10;
	SetPos(12, j);cout << ">>";
	while (1)
	{
		if (_kbhit())
		{
			int key = _getch();
			if (key == 224)
			{
				int arrow = _getch();
				switch (arrow)
				{
				case 72:
					if(j>10){PlaySelectSound();SetPos(12,j);cout<<" ";j-=2;SetPos(12,j);cout<<">>";}break;
				case 80:
					if(j<18){PlaySelectSound();SetPos(12,j);cout<<" ";j+=2;SetPos(12,j);cout<<">>";}break;
				}
			}
			else if (key == 'k')
			{
				if(j ==10) return 1;
				else if(j ==12) return 2;
				else if(j ==14) return 3;
				else if(j ==16) return 4;
				else if(j ==18){DrawHelpText();return 5;}
			}
		}
	}
}

class Game
{
public:
	COORD position[10];
	COORD bullet[50];
	COORD bulletOldPos[50];
	Frame enemy[20];
	int score;
	int oldScore;
	int speedInterval;
	const int MIN_INTERVAL = 20;
	int shootCd;
	const int CD_MAX = 6;
	string title;
	bool hardMode;
	bool isEndlessMode;
	int level;
	int enemyShootTimer[8];
	
	int ultCooldownTick;
	const int ULT_FIXED_TICK = 1250;
	int lastMoveKey;
	void FireUlt();
	
	Frame boss;
	bool bossExist;
	bool bossWarningDone;
	bool isWinGame;
	bool nextLevelFlag;
	int bossHp;
	int bossTimerShoot;
	int bossTimerSpawnEnemy;
	int bossMoveDir;
	
	char msgBuf[40];
	int msgTimer;
	
	Game();
	void initPlane();
	void initBullet();
	void initEnemy();
	void planeMove(int keyCode);
	void bulletMove();
	void enemyMove();
	void UpdatePlusBullets();
	void CheckShootEnemyFire();
	void ShowBossWarning();
	void drawPlane();
	void drawPlaneToNull();
	void drawBullet();
	void drawBulletToNull();
	void drawEnemyAll();
	void eraseEnemyAll();
	void drawThisBulletToNull(COORD);
	void drawThisEnemyToNull(Frame);
	void drawExplosion(Frame &f);
	void UpdateExplosion();
	void DrawBoss();
	void ClearBoss();
	void Pause();
	void Playing();
	void judgePlane();
	void judgeEnemy();
	void Shoot();
	void GameOver();
	void GameWin();
	void NextEndlessLevel();
	void printScore();
	void printUltStatus();
	string getTitleByScore(int s);
	void getNextInfo(int s, int& need, string& nextT);
	void SetTempMsg(const char* text);
	void UpdateTempMsg();
};

void Game::FireUlt()
{
	if(ultCooldownTick > 0) return;
	PlayUltSound();
	int startX = position[5].X - 24;
	for(int d = 0; d < 50; d++)
	{
		int bx = startX + d;
		if(bx < 1 || bx > 47) continue;
		for(int i = 0; i < 50; i++)
		{
			if(bullet[i].Y == 30)
			{
				bullet[i].X = (short)bx;
				bullet[i].Y = (short)(position[5].Y - 1);
				bulletOldPos[i] = bullet[i];
				break;
			}
		}
	}
	ultCooldownTick = ULT_FIXED_TICK;
}

Game::Game()
{
	initPlane();
	initBullet();
	initEnemy();
	score = 0;
	oldScore = -1;
	speedInterval = 35;
	shootCd = 0;
	title = "实习飞行员";
	hardMode = false;
	isEndlessMode = false;
	level = 1;
	for(int i = 0; i < 8; i++) enemyShootTimer[i] = 0;
	ultCooldownTick = 0;
	lastMoveKey = -1;
	
	bossExist = false;
	bossWarningDone = false;
	isWinGame = false;
	nextLevelFlag = false;
	bossHp = 100;
	bossTimerShoot = 0;
	bossTimerSpawnEnemy = 0;
	bossMoveDir = 1;
	savePosToOld(boss);
	
	msgBuf[0] = 0;
	msgTimer = 0;
}

void Game::SetTempMsg(const char* text)
{
	strncpy_s(msgBuf, text, sizeof(msgBuf)-1);
	msgTimer = 25;
}
void Game::UpdateTempMsg()
{
	if(msgTimer >0)
	{
		SetPos(10, 1);
		cout << msgBuf;
		msgTimer--;
		if(msgTimer <=0)
		{
			drawRow(1,10,40,' ');
			msgBuf[0]=0;
		}
	}
}

string Game::getTitleByScore(int s)
{
	if(isEndlessMode) return "";
	if (s < 120) return "实习飞行员";
	else if (s < 360) return "初级飞行员";
	else if (s < 480) return "中级飞行员";
	else if (s < 700) return "高级飞行员";
	else return "王牌飞行员";
}
void Game::getNextInfo(int s, int& need, string& nextT)
{
	if(isEndlessMode){ need=0; nextT=""; return; }
	if (s < 120) { need = 120 - s; nextT = "初级飞行员"; }
	else if (s < 360) { need = 360 - s; nextT = "中级飞行员"; }
	else if (s < 480) { need = 480 - s; nextT = "高级飞行员"; }
	else if (s < 700) { need = 700 - s; nextT = "王牌飞行员"; }
	else { need = 0; nextT = "已满级"; }
}
void Game::initPlane()
{
	COORD centren = { (short)39, (short)22 };
	position[0].X = position[5].X = position[7].X = position[9].X = centren.X;
	position[1].X = (short)(centren.X - 2);
	position[2].X = position[6].X = (short)(centren.X - 1);
	position[3].X = position[8].X = (short)(centren.X + 1);
	position[4].X = (short)(centren.X + 2);
	for (int i = 0; i <= 4; i++) position[i].Y = centren.Y;
	position[5].Y = (short)(centren.Y - 1);
	for (int i = 6; i <= 8; i++) position[i].Y = (short)(centren.Y + 1);
	position[9].Y = (short)(centren.Y - 2);
}
void Game::drawPlane()
{
	for (int i = 0; i < 10; i++)
	{
		SetPos(position[i]);
		if (i == 5) cout << "|";
		else cout << "O";
	}
}
void Game::drawPlaneToNull()
{
	for (int i = 0; i < 10; i++)
	{
		SetPos(position[i]);
		cout << " ";
	}
}
void Game::initBullet()
{
	for (int i = 0; i < 50; i++)
	{
		bullet[i].Y = (short)30;
		bulletOldPos[i].Y = (short)30;
	}
}

void Game::drawBullet()
{
	for (int i = 0; i < 50; i++)
	{
		if (bullet[i].Y != 30)
		{
			if (bulletOldPos[i].Y != 30)
			{
				SetPos(bulletOldPos[i]);
				cout << " ";
			}
			SetPos(bullet[i]);
			cout << "^";
			bulletOldPos[i] = bullet[i];
		}
		else
		{
			if (bulletOldPos[i].Y != 30)
			{
				SetPos(bulletOldPos[i]);
				cout << " ";
			}
			bulletOldPos[i].Y = (short)30;
		}
	}
}

void Game::drawBulletToNull()
{
	for (int i = 0; i < 50; i++)
	{
		if (bullet[i].Y != 30)
		{
			SetPos(bullet[i]);
			cout << " ";
		}
		bullet[i].Y = (short)30;
		if (bulletOldPos[i].Y != 30)
		{
			SetPos(bulletOldPos[i]);
			cout << " ";
		}
		bulletOldPos[i].Y = (short)30;
	}
}
void Game::initEnemy()
{
	for(int i = 0; i < 8; i++)
		SpawnEnemy(enemy[i]);
	for(int i = 8; i < 20; i++){
		enemy[i].hp = 0;
		enemy[i].type = -1;
		enemy[i].explodeTimer =0;
		savePosToOld(enemy[i]);
	}
}
void Game::drawEnemyAll()
{
	for (int i = 0; i < 20; i++)
	{
		if(enemy[i].hp >0 || enemy[i].explodeTimer>0) DrawEnemyByType(enemy[i]);
	}
}
void Game::eraseEnemyAll()
{
	for (int i = 0; i < 20; i++)
	{
		if(enemy[i].hp >0 || enemy[i].explodeTimer>0)
		{
			clearRect(enemy[i]);
		}
	}
}
void Game::drawThisEnemyToNull(Frame f)
{
	clearRect(f);
}
void Game::drawExplosion(Frame &f)
{
	PlayExplodeSound();
	f.hp = 0;
	f.explodeTimer = 10;
}
void Game::UpdateExplosion()
{
	for(int i=0;i<20;i++)
	{
		if(enemy[i].explodeTimer>0)
		{
			enemy[i].explodeTimer--;
			if(enemy[i].explodeTimer <=0)
			{
				clearRect(enemy[i]);
				enemy[i].type = -1;
			}
		}
	}
}

void Game::DrawBoss()
{
	if(!bossExist) return;
	drawFrame(boss.position[0],boss.position[1],'@','#');
}
void Game::ClearBoss()
{
	clearRect(boss);
}

void Game::ShowBossWarning()
{
	PlayBossWarning();
	for(int t = 0; t < 3; t++)
	{
		SetPos(28, 10);
		cout << "!!!! BOSS 来袭 !!!!";
		Sleep(500);
		SetPos(28, 10);
		cout << "                    ";
		Sleep(500);
	}
	SetPos(28, 10);
	cout << "!!!! BOSS 来袭 !!!!";
	Sleep(1000);
	drawRow(10,28,46,' ');
}

void Game::CheckShootEnemyFire()
{
	for(int i = 0; i < 8; i++)
	{
		if(enemy[i].hp <= 0) continue;
		if(enemy[i].type != ENEMY_SHOOT) continue;
		enemyShootTimer[i]++;
		if(enemyShootTimer[i] >= 63)
		{
			enemyShootTimer[i] = 0;
			for(int slot = 8; slot < 20; slot++)
			{
				if(enemy[slot].hp <= 0 && enemy[slot].explodeTimer <=0)
				{
					SpawnPlusEnemy(enemy[slot], enemy[i].position[0].X + 1, enemy[i].position[1].Y + 1);
					enemy[slot].hp = 1;
					break;
				}
			}
		}
	}
}

void Game::UpdatePlusBullets()
{
	for(int i = 8; i < 20; i++)
	{
		if(enemy[i].hp >0 && enemy[i].type == ENEMY_PLUS)
		{
			clearOldRect(enemy[i]);
			enemy[i].position[0].Y +=2;
			enemy[i].position[1].Y +=2;
			savePosToOld(enemy[i]);
			if(enemy[i].position[1].Y >=23)
			{
				clearRect(enemy[i]);
				enemy[i].hp =0;
				enemy[i].type =-1;
			}
		}
	}
}

void Game::Pause()
{
	drawRow(2, 61, 79, ' ');
	SetPos(61, 2);
	cout << "暂停中...按p继续";
	int c = _getch();
	while (c != 'p') c = _getch();
	drawRow(2, 61, 79, ' ');
}
void Game::planeMove(int keyCode)
{
	bool moved = false;
	if (keyCode == 75)
		if (position[1].X > 1)
		{
			for (int i = 0; i < 10; i++) position[i].X = (short)(position[i].X - 1);
			moved = true;
		}
	if (keyCode == 80)
		if (position[7].Y < 23)
		{
			for (int i = 0; i < 10; i++) position[i].Y = (short)(position[i].Y + 1);
			moved = true;
		}
	if (keyCode == 77)
		if (position[4].X < 47)
		{
			for (int i = 0; i < 10; i++) position[i].X = (short)(position[i].X + 1);
			moved = true;
		}
	if (keyCode == 72)
		if (position[9].Y > 3)
		{
			for (int i = 0; i < 10; i++) position[i].Y = (short)(position[i].Y - 1);
			moved = true;
		}
	if(moved && lastMoveKey != keyCode)
	{
		PlayPlaneMoveSound();
		lastMoveKey = keyCode;
	}
	else if(!moved)
	{
		lastMoveKey = -1;
	}
}
void Game::bulletMove()
{
	for (int i = 0; i < 50; i++)
	{
		if (bullet[i].Y != 30)
		{
			bullet[i].Y = (short)(bullet[i].Y - 1);
			if (bullet[i].Y <= 1)
			{
				bullet[i].Y = (short)30;
			}
		}
	}
}
void Game::enemyMove()
{
	for (int i = 0; i < 8; i++)
	{
		if(enemy[i].hp <= 0) continue;
		clearOldRect(enemy[i]);
		int step = 1;
		for(int s = 0; s < step; s++)
		{
			enemy[i].position[0].Y++;
			enemy[i].position[1].Y++;
			if (enemy[i].position[1].Y >= 23)
			{
				SpawnEnemy(enemy[i]);
				enemyShootTimer[i] = 0;
				break;
			}
		}
		savePosToOld(enemy[i]);
	}
	
	if(bossExist)
	{
		clearOldRect(boss);
		int bLeft = boss.position[0].X;
		int bRight = boss.position[1].X;
		if(bLeft <= 2) bossMoveDir = 1;
		if(bRight >= 44) bossMoveDir = -1;
		boss.position[0].X += (short)bossMoveDir;
		boss.position[1].X += (short)bossMoveDir;
		savePosToOld(boss);
	}
}

void Game::NextEndlessLevel()
{
	score = 0;
	level++;
	if(speedInterval>22)speedInterval--;
	initEnemy();
	initBullet();
	bossExist = false;
	bossWarningDone = false;
	bossHp = 100;
	bossTimerShoot =0;
	bossTimerSpawnEnemy =0;
	bossMoveDir =1;
	nextLevelFlag = false;
	system("cls");
	drawPlayingUI(true);
}

void Game::judgePlane()
{
	for (int i = 0; i < 20; i++)
	{
		if(enemy[i].hp <= 0) continue;
		for (int j = 0; j < 10; j++)
			if (judgeCoordInFrame(enemy[i], position[j]))
			{
				drawRow(1, 62, 70, ' ');
				SetPos(62, 1);
				cout << "坠毁";
				drawFrame(enemy[i], '+', '+');
				PlayCrashSound();
				Sleep(1000);
				GameOver();
				return;
			}
	}
	if(bossExist)
	{
		for(int j = 0; j < 10; j++)
		{
			if(judgeCoordInFrame(boss, position[j]))
			{
				drawRow(1, 62, 70, ' ');
				SetPos(62, 1);cout << "坠毁";
				PlayCrashSound();Sleep(1000);
				GameOver();return;
			}
		}
	}
}

void Game::drawThisBulletToNull(COORD c)
{
	SetPos(c);
	cout << " ";
}
void Game::judgeEnemy()
{
	for (int i = 0; i < 20; i++)
	{
		if(enemy[i].hp <= 0) continue;
		for (int j = 0; j < 50; j++)
		{
			if (judgeCoordInFrame(enemy[i], bullet[j]))
			{
				enemy[i].hp--;
				drawThisBulletToNull(bullet[j]);
				bullet[j].Y = (short)30;
				bulletOldPos[j].Y = (short)30;
				
				if(enemy[i].hp > 0)
				{
					PlayHitSound();
					return;
				}
				clearRect(enemy[i]);
				int addScore;
				if(enemy[i].type == ENEMY_SHOOT) addScore = 10;
				else if(enemy[i].type == ENEMY_HEAVY) addScore = 15;
				else if(enemy[i].type == ENEMY_PLUS) addScore = 10;
				else addScore = 5;
				if(hardMode) addScore *= 2;
				
				score += addScore;
				drawExplosion(enemy[i]);
				
				if(i < 8)
				{
					SpawnEnemy(enemy[i]);
					enemyShootTimer[i] = 0;
				}
				printScore();
				
				if(isEndlessMode && score >=300)
				{
					nextLevelFlag = true;
				}
				return;
			}
		}
	}
	if(bossExist)
	{
		for(int j = 0; j < 50; j++)
		{
			if(bullet[j].Y == 30) continue;
			if(judgeCoordInFrame(boss, bullet[j]))
			{
				bossHp--;
				drawThisBulletToNull(bullet[j]);
				bullet[j].Y = 30;
				bulletOldPos[j].Y = (short)30;
				PlayHitSound();
				if(bossHp <= 0)
				{
					ClearBoss();
					bossExist = false;
					if(!isEndlessMode)
					{
						isWinGame = true;
					}
				}
			}
		}
	}
}
void Game::Shoot()
{
	if (shootCd > 0) return;
	for (int i = 0; i < 50; i++)
		if (bullet[i].Y == 30)
		{
			bullet[i].X = position[5].X;
			bullet[i].Y = (short)(position[5].Y - 1);
			bulletOldPos[i] = bullet[i];
			shootCd = CD_MAX;
			break;
		}
	
}

void Game::printUltStatus()
{
	drawRow(9,60,78,' ');
	SetPos(60,9);
	if(ultCooldownTick > 0)
	{
		int sec = ultCooldownTick / 125;
		cout<<sec<<"s冷却";
	}
	else
	{
		cout<<"【就绪】";
	}
}

void Game::printScore()
{
	if(score == oldScore) return;
	oldScore = score;
	int nextNeed = 0;
	string nextTitle = "";
	title = getTitleByScore(score);
	getNextInfo(score, nextNeed, nextTitle);
	
	if(!isEndlessMode)
	{
		int base = speedInterval;
		if (score >= 120 && base > MIN_INTERVAL) base -=1;
		if (score >= 360 && base > MIN_INTERVAL) base -=1;
		if (score >= 480 && base > MIN_INTERVAL) base -=1;
		if (score >= 700 && base > MIN_INTERVAL) base -=1;
		if(base < MIN_INTERVAL) base = MIN_INTERVAL;
		speedInterval = base;
	}
	
	drawRow(6, 60, 78, ' ');
	SetPos(60, 6); cout << score;
	if(!isEndlessMode)
	{
		drawRow(7, 60, 78, ' ');
		SetPos(60, 7); cout << title;
		drawRow(8, 60, 78, ' ');
		SetPos(60, 8);
		if(nextNeed>0) cout << nextNeed << "分->" << nextTitle;
		else cout << nextTitle;
	}
	else
	{
		drawRow(7,60,78,' ');
		SetPos(60,7);cout<<"第"<<level<<"关";
		drawRow(8,60,78,' ');
		SetPos(60,8);cout<<"目标:300分";
	}
	printUltStatus();
}

void Game::GameWin()
{
	PlayWinSound();
	StopAllSound();
	system("cls");
	drawRow(6, 10, 65, '=');
	drawRow(14, 10, 65, '=');
	drawCol(10, 7, 13, '|');
	drawCol(65, 7, 13, '|');
	SetPos(28, 8);  cout << "You win !";
	SetPos(24, 10); cout << "击落敌机:" << score / 5 << " 架";
	SetPos(24, 11); cout << "得  分:" << score;
	if(!isEndlessMode)
		SetPos(24, 12); cout << "获得称号:" << getTitleByScore(score);
	Sleep(1500);
	system("cls");
	drawRow(4, 8, 67, '=');
	drawRow(18, 8, 67, '=');
	drawCol(8, 5, 17, '|');
	drawCol(67, 5, 17, '|');
	SetPos(26, 6);  cout << "击落敌机:" << score / 5 << " 架";
	SetPos(26, 8);  cout << "得  分:" << score;
	if(!isEndlessMode)
		SetPos(26, 10); cout << "获得称号:" << getTitleByScore(score);
	SetPos(26, 12); cout << "恭喜通关全部内容!";
	SetPos(10, 20);
	cout << "继续? 是(y) | 否(n)";
	as_win:
	int x = _getch();
	if (x == 'n') exit(0);
	else if (x == 'y')
	{
		system("cls");
		Game newGame;
		int sel;
		do
		{
			sel = drawMenu();
		}while(sel == 5);
		if(sel == 2 || sel ==4)
		{
			newGame.hardMode = true;
			newGame.speedInterval = 23;
		}
		else
		{
			newGame.hardMode = false;
			newGame.speedInterval = 35;
		}
		if(sel ==3 || sel ==4) newGame.isEndlessMode = true;
		
		system("cls");
		drawPlayingUI(newGame.isEndlessMode);
		newGame.Playing();
	}
	else goto as_win;
}

void Game::Playing()
{
	//进入对局:关闭菜单BGM,开启战斗BGM
	StopAllSound();
	StartBattleBGM();
	
	drawEnemyAll();
	DrawBoss();
	drawPlane();
	printScore();
	int flag_bullet = 0;
	int flag_enemy = 0;
	const int FRAME_SLEEP = 8;
	while (1)
	{
		Sleep(FRAME_SLEEP);
		UpdateTempMsg();
		UpdateExplosion();
		
		if(bossExist)
		{
			bossTimerShoot++;
			bossTimerSpawnEnemy++;
			if(bossTimerShoot >= 625)
			{
				bossTimerShoot = 0;
				SetTempMsg("BOSS:发射炮弹!");
				int totalW = boss.position[1].X - boss.position[0].X;
				for(int b = 0; b < 25; b++)
				{
					int slot = -1;
					for(int s = 8; s < 20; s++)
					{
						if(enemy[s].hp <=0 && enemy[s].explodeTimer <=0)
						{
							slot = s;
							break;
						}
					}
					if(slot == -1) break;
					int spawnX = boss.position[0].X + (b * totalW)/24;
					if(spawnX <1) spawnX=1;
					if(spawnX>47) spawnX=47;
					SpawnPlusEnemy(enemy[slot], spawnX, boss.position[1].Y + 1);
					enemy[slot].hp =1;
				}
			}
			if(bossTimerSpawnEnemy >= 250)
			{
				bossTimerSpawnEnemy = 0;
				SetTempMsg("BOSS:投放敌机!");
				int cnt = 0;
				for(int k = 0; k < 8;k++)
				{
					if(enemy[k].hp <= 0 && cnt <7)
					{
						SpawnEnemy(enemy[k]);
						cnt++;
					}
				}
			}
		}
		else
		{
			if(!isEndlessMode)
			{
				if(score >= 700 && !bossWarningDone)
				{
					bossWarningDone = true;
					ShowBossWarning();
					bossExist = true;
					bossHp = 100;
					bossTimerShoot = 0;
					bossTimerSpawnEnemy = 0;
					bossMoveDir = 1;
					boss.position[0].X = 10;
					boss.position[0].Y = 2;
					boss.position[1].X = 30;
					boss.position[1].Y = 6;
					savePosToOld(boss);
					PlayBossAppear();
				}
			}
			else
			{
				if( (level%3 ==0) && !bossWarningDone )
				{
					bossWarningDone = true;
					ShowBossWarning();
					bossExist = true;
					bossHp = 100;
					bossTimerShoot = 0;
					bossTimerSpawnEnemy = 0;
					bossMoveDir = 1;
					boss.position[0].X = 10;
					boss.position[0].Y = 2;
					boss.position[1].X = 30;
					boss.position[1].Y = 6;
					savePosToOld(boss);
					PlayBossAppear();
				}
			}
		}
		
		CheckShootEnemyFire();
		UpdatePlusBullets();
		
		if(isWinGame)
		{
			GameWin();
			break;
		}
		if(nextLevelFlag)
		{
			PlayWinSound();
			StopAllSound();
			system("cls");
			SetPos(22,10);cout<<"=====You Win! 进入第"<<(level+1)<<"关=====";
			Sleep(1200);
			NextEndlessLevel();
			StartBattleBGM();
			drawEnemyAll();
			DrawBoss();
			drawPlane();
			printScore();
		}
		
		if(ultCooldownTick > 0) ultCooldownTick--;
		
		if (shootCd > 0) shootCd--;
		if (_kbhit())
		{
			int key = _getch();
			if (key == 224)
			{
				int arrow = _getch();
				drawPlaneToNull();
				planeMove(arrow);
				drawPlane();
				judgePlane();
			}
			else if (key == 'p') Pause();
			else if (key == 'k') Shoot();
			else if(key == 'f') FireUlt();
			else if (key == 'e')
			{
				GameOver();
				break;
			}
		}
		
		if (flag_bullet == 0)
		{
			bulletMove();
			drawBullet();
			judgeEnemy();
			judgePlane();
		}
		flag_bullet = (flag_bullet + 1) % 7;
		
		if (flag_enemy == 0)
		{
			enemyMove();
		}
		drawEnemyAll();
		if(bossExist) DrawBoss();
		drawFrame(0, 0, 48, 24, '=', '|');
		judgePlane();
		
		flag_enemy = (flag_enemy + 1) % speedInterval;
		printUltStatus();
	}
}

void Game::GameOver()
{
	PlayCrashSound();
	StopAllSound();
	system("cls");
	drawRow(6, 10, 65, '=');
	drawRow(12, 10, 65, '=');
	drawCol(10, 7, 11, '|');
	drawCol(65, 7, 11, '|');
	SetPos(30, 8); cout << "Game Over!";
	Sleep(1000);
	system("cls");
	drawRow(4, 8, 67, '=');
	drawRow(19, 8, 67, '=');
	drawCol(8, 5, 18, '|');
	drawCol(67, 5, 18, '|');
	SetPos(26, 6);  cout << "击落敌机:" << score / 5 << " 架";
	SetPos(26, 8);  cout << "得  分:" << score;
	
	//修复无尽模式结算:不显示称号,改为显示坚持到第几关
	if(isEndlessMode)
	{
		SetPos(26, 10); cout << "你坚持到了:第" << level << "关";
	}
	else
	{
		SetPos(26, 10); cout << "获得称号:" << getTitleByScore(score);
		SetPos(10, 13); cout << "0~119分   实习飞行员";
		SetPos(10, 14); cout << "120~359分 初级飞行员";
		SetPos(10, 15); cout << "360~479分 中级飞行员";
		SetPos(10, 16); cout << "480~699分 高级飞行员";
		SetPos(10, 17); cout << "≥700分    王牌飞行员";
	}
	
	SetPos(10, 21);
	cout << "继续? 是(y) | 否(n)";
	as_over:
	int x = _getch();
	if (x == 'n') exit(0);
	else if (x == 'y')
	{
		system("cls");
		Game newGame;
		int sel;
		do
		{
			sel = drawMenu();
		}while(sel == 5);
		if(sel ==2 || sel ==4)
		{
			newGame.hardMode = true;
			newGame.speedInterval = 23;
		}
		else
		{
			newGame.hardMode = false;
			newGame.speedInterval = 35;
		}
		if(sel ==3 || sel ==4) newGame.isEndlessMode = true;
		
		system("cls");
		drawPlayingUI(newGame.isEndlessMode);
		newGame.Playing();
	}
	else goto as_over;
}

int main()
{
	DisableQuickEdit();
	SetConsoleTitleW(L"飞机大战 v3.1");
	srand((unsigned)time(NULL));
	HideCursor();
	
	system("cls");
	
	for(int y = 0; y <= 8; y++)
	{
		system("cls");
		SetPos(30, y);
		cout << "================";
		SetPos(33, y + 1);
		cout << "飞机大战";
		SetPos(38, y + 2);
		cout << "v3.1";
		SetPos(30, y + 3);
		cout << "================";
		if(y % 3 == 2) PlayTitleEnterSound();
		Sleep(90);
	}
	
	SetPos(28, 13);
	cout << "制作:JohnShu";
	SetPos(24, 15);
	cout << "【原创游戏,假冒必究】";
	Sleep(2200);
	
	StartHelpBGM();
	for(int i=0;i<=100;i++)
	{
		system("cls");
		cout<<"--------------------------------------------"<<endl;
		cout<<"  游戏:飞机大战v3.1        ------------------------------"<<endl;
		cout<<"  【敌机】普通|快速|重甲|射击敌机|BOSS"<<endl;
		cout<<"  【操作】方向键移动,k射击,f大招,p暂停,e退出"<<endl;
		cout<<"  【提示】请务必切换英文输入法,防止按键失效!"<<endl;
		cout<<"  正在加载:"<<i<<'%'<<"-----------------------------"<<endl;
		cout<<"--------------------------------------------"<<endl;
		Sleep(100);
	}
	
	system("cls");
	cout<<"--------------------------------------------"<<endl;
	cout<<"        飞机大战 v3.1"<<endl;
	cout<<"        是否查看玩法引导?"<<endl;
	cout<<"        按【y】查看,其他键跳过"<<endl;
	cout<<"--------------------------------------------"<<endl;
	int ch = _getch();
	if(ch == 'y' || ch == 'Y')
	{
		DrawHelpText();
	}
	StopAllSound();
	
	system("cls");
	
	Game game;
	int sel;
	do
	{
		sel = drawMenu();
	}while(sel == 5);
	
	if(sel == 2 || sel ==4)
	{
		game.hardMode = true;
		game.speedInterval = 23;
	}
	else
	{
		game.hardMode = false;
		game.speedInterval = 35;
	}
	if(sel ==3 || sel ==4)
	{
		game.isEndlessMode = true;
	}
	
	system("cls");
	drawPlayingUI(game.isEndlessMode);
	game.Playing();
	return 0;
}

© 版权声明

JohnShu原创 | 未经作者授权,禁止私自转载、商用、篡改二次发布,仅供个人学习交流使用。