无任何格外需求的命令行C++飞机大战,内含BOSS,动画,万行代码!免费奉上!

news2024/11/25 6:56:11

个程序的源码没有什么技术要求,一般至少能看懂95%,因为博主是大一上学期写着玩的,当写了一周,还拿它参加了学校的创意编程比赛,结果第一用的ui,直接降维打击了,拿了个二等奖

 

 

操作方法游戏内都有

注意事项:1在动画时不能乱按
     2小怪设计的初衷是躲避,因此碰到就直接死(主要是我当初没想到我能把敌方子弹射击出来)
     3子弹按的速度过快会在某个点停下来,困难模式基本不会有这种情况,狂按就完了
     4由于小怪主要设计是躲避,所以子弹给的比较少,到BOSS时会自动增加,足够用
     5积分达到200时BOSS就会出现,BOSS四个技能,其中激光碰到大概率会直接死
     6尽量选择普通和困难,简单模式太弱智了

游戏思路:控制光标移动,通过坐标定点输出起到子弹移动,飞机移动效果和动画效果。
                 以不同数组分别存放我方与敌方的子弹坐标,理论上增加数组就可以增加子弹种类


缺点:就是移动僵硬,不能使长按速度保持稳定,所以点按玩起来效果更好。
          我方飞机不够没观,敌机种类较少
          没有音效(是一个遗憾)

大家有什么问题欢迎评论或私信问我哦,博主现在大一,一般一天之内就可以回复。

因为这个程序是一个多月前写的,有些重要的东西我可能没有说,欢迎提问!

头文件:

#include<iostream>
#include<Windows.h>
#include<conio.h>
#include<cstdlib>
#include<time.h>
#include<stdlib.h>
#include<cmath>
#include"menu.h"
 
//飞机活动大小
#define width 80
#define height 40
//窗口大小
#define t_width 120
#define t_height 40
 
void gotoxy(short x, short y);
void Game();
 
void enemyAppear(char arr[width + 10][height]);
void enemyMove(char arr[width + 10][height]);
 
void bulletMove(char arr[width + 10][height]);
void BOSSgame();
void shotBOSS(char arr[width + 10][height]);
void difficulty();
 
void cartoonStartMenu();
void start_menu();
void game_menu();
void cartoonGameMenu();
void end_menu();
void success_menu();
void BOSScartoon();
void printBOSS();

全局变量:

这部分主要是调节难度用的

extern int score = 0;
extern int bullet = 99999;
extern int HP = 100000;
extern int BOSSHP = 500;
extern int damage = 3;
extern int enemySpeed = 10;
extern int BOSSspeed = 15;
extern int Number = 4;
extern int BOSS = 0;
 

最难的部分:

该部分是我认为命令行实现按键移动的关键,如果只是想试玩一下只要知道函数功能就够了

深入了解handle(句柄)我推荐:控制台API函数----HANDLE、SetConsoleCursorPosition、SetConsoleTextAttribute_weixin_30901729的博客-CSDN博客

//清除光标
void clearCursor()
{
	HANDLE hOut;
	CONSOLE_CURSOR_INFO cur = { 1,0 };
	hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorInfo(hOut, &cur);
}
 
 
//使光标移动到指定位置
void gotoxy(short x, short y)
{
	HANDLE hOut;
	hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD pos = { x,y };
	SetConsoleCursorPosition(hOut, pos);
}

存子弹和飞机位置的数组:

char enemyArr[width + 10][height] = { 0 };
char myBulletArr[width + 10][height] = { 0 };

我方飞机的子弹射击,移动

//飞机图像
void printPlane(short x, short y)
{
	gotoxy(x, y);
	cout << "*";//头
	gotoxy(x, y + 1);
	cout << "*";//尾
	gotoxy(x - 1, y + 1);
	cout << "*";//左翼
	gotoxy(x + 1, y + 1);
	cout << "*";//右翼
}
 
 
class myPlane
{
public:
	//头的坐标
	short x = width / 2;
	short y = height / 2;
 
 
 
	//初始化飞机
	void initMyPlane()
	{
		printPlane(x, y);
	}
 
	//清除飞机移动前位置图像
	void clearMyplane()
	{
		gotoxy(x, y);
		cout << " ";//头
		gotoxy(x, y + 1);
		cout << " ";//尾
		gotoxy(x - 1, y + 1);
		cout << " ";//左翼
		gotoxy(x + 1, y + 1);
		cout << " ";//右翼
	}
 
 
	//射击
	void shoot(char myArr[width + 10][height])
	{
		if (bullet == 0)
			return;
		myArr[x][y - 1] = '*';
		gotoxy(x, y - 1);
		cout << "*";
		bullet--;
		gotoxy(width + (t_width - width) / 2, 9);
		cout << "   ";
		gotoxy(width + (t_width - width) / 2, 9);
		cout << bullet;
	}
 
	//飞机移动+游戏中的菜单栏功能实现
	void myPlaneMove(char arr[width + 10][height])
	{
		//判断是否有键盘操作
		if (_kbhit())
		{
			char move;
			move = _getch();
			switch (move)
			{
			case 'w':
				if (BOSS == 1)
					if (y == 16)
						break;
				//判断是否是边界
				if (y == 1)
					break;
				//清除原图像
				clearMyplane();
				y--;
				//打印新位置
				printPlane(x, y);
				break;
			case 'a':
				if (x - 1 == 1)
					break;
				clearMyplane();
				x--;
				printPlane(x, y);
				break;
			case 's':
				if (y + 1 == height - 2)
					break;
				clearMyplane();
				y++;
				printPlane(x, y);
				break;
			case 'd':
				if (x + 1 == width - 2)
					break;
				clearMyplane();
				x++;
				printPlane(x, y);
				break;
			case 'j':
				shoot(myBulletArr);
			case 'W':
				if (BOSS == 1)
					if (y == 16)
						break;
				//判断是否是边界
				if (y == 1)
					break;
				//清除原图像
				clearMyplane();
				y--;
				//打印新位置
				printPlane(x, y);
				break;
			case 'A':
				if (x - 1 == 1)
					break;
				clearMyplane();
				x--;
				printPlane(x, y);
				break;
			case 'S':
				if (y + 1 == height - 2)
					break;
				clearMyplane();
				y++;
				printPlane(x, y);
				break;
			case 'D':
				if (x + 1 == width - 2)
					break;
				clearMyplane();
				x++;
				printPlane(x, y);
				break;
            //控制射击
			case 'J':
				shoot(myBulletArr);
			}
		}
	}
};
 
myplane p;//创捷我方飞机

难度参数设置:

//难度选择
void difficulty()
{
	gotoxy(t_width / 2 - 5, t_height / 2 - 4);
	cout << "1.简单模式";
	gotoxy(t_width / 2 - 5, t_height / 2);
	cout << "2.普通模式";
	gotoxy(t_width / 2 - 5, t_height / 2 + 4);
	cout << "3.困难模式";
	char choice;
	choice = _getch();
	switch (choice)
	{
	case '1':
		enemySpeed = 50;
		BOSSspeed = 25;
		HP = 1000;
		damage = 5;
		bullet = 50;
		Number = 2;
		break;
	case '2':
		enemySpeed = 10;
		BOSSspeed = 15;
		HP = 500;
		damage = 3;
		bullet = 30;
		Number = 4;
		break;
	case '3':
		enemySpeed = 8;
		BOSSspeed = 5;
		HP = 100;
		damage = 2;
		bullet = 10;
		Number = 6;
		break;
	}
 
}

子弹功能实现:

void shotEnemy(char enemyArr[width + 10][height], char myArr[width + 10][height])
{
	for (int i = 2; i < width; i++)
		for (int j = 2; j < height; j++)
		{
			if (myArr[i][j] == '*' || myArr[i][j] == '@')
			{
				//碰头
				if (enemyArr[i][j - 2] == '+')
				{
					myArr[i][j] = '@';
 
					gotoxy(i, j - 1);
					cout << "*";
				}
				//碰左翼
				else if (enemyArr[i][j - 2] == 'p')
				{
					myArr[i][j] = '@';
 
					gotoxy(i, j - 1);
					cout << "*";
				}
				//碰右翼
				else if (enemyArr[i][j - 2] == 'q')
				{
					myArr[i][j] = '@';
 
					gotoxy(i, j - 1);
					cout << "*";
				}
				//碰头
				if (enemyArr[i][j - 1] == '+')
				{
					myArr[i][j] = 0;
					enemyArr[i][j - 1] = 0;
					enemyArr[i - 1][j - 2] = 0;
					enemyArr[i + 1][j - 2] = 0;
					enemyArr[i][j - 2] = 0;
 
 
					gotoxy(i, j - 1);
					cout << " ";
					gotoxy(i - 1, j - 2);
					cout << " ";
					gotoxy(i + 1, j - 2);
					cout << " ";
					gotoxy(i, j - 2);
					cout << " ";
					gotoxy(i, j);
					cout << " ";
 
				}
 
				//碰左翼
				else if (enemyArr[i][j - 1] == 'p')
				{
					myArr[i][j] = 0;
					enemyArr[i][j - 1] = 0;
					enemyArr[i - 1][j] = 0;
					enemyArr[i - 1][j - 1] = 0;
					enemyArr[i - 2][j - 1] = 0;
 
 
					gotoxy(i, j - 1);
					cout << " ";
					gotoxy(i - 1, j);
					cout << " ";
					gotoxy(i - 1, j - 1);
					cout << " ";
					gotoxy(i - 2, j - 1);
					cout << " ";
					gotoxy(i, j);
					cout << " ";
				}
 
				//碰右翼
				else if (enemyArr[i][j - 1] == 'q')
				{
					myArr[i][j] = 0;
					enemyArr[i][j - 1] = 0;
					enemyArr[i + 1][j] = 0;
					enemyArr[i + 1][j - 1] = 0;
					enemyArr[i + 2][j - 1] = 0;
 
 
					gotoxy(i, j - 1);
					cout << " ";
					gotoxy(i + 1, j);
					cout << " ";
					gotoxy(i + 1, j - 1);
					cout << " ";
					gotoxy(i + 2, j - 1);
					cout << " ";
					gotoxy(i, j);
					cout << " ";
				}
 
 
 
			}
		}
}
 
//子弹移动
void bulletMove(char myArr[width + 10][height])
{
	for (int i = 2; i < width; i++)
		for (int j = 2; j < height; j++)
		{
			if (myArr[i][j] == '*')
			{
				myArr[i][j] = 0;
				myArr[i][j - 1] = '*';
				gotoxy(i, j - 1);
				cout << "*";
				gotoxy(i, j);
				cout << " ";
			}
 
		}
 
	//清除触界子弹
	for (int k = 1; k < width; k++)
	{
		if (myArr[k][1] == '*')
		{
			gotoxy(k, 1);
			cout << " ";
			myArr[k][1] = 0;
		}
	}
}

敌机设置:

//随机出现敌机
void enemyAppear(char enemyArr[width + 10][height])
{
	srand((unsigned int)time(NULL));
	//随机敌机数量
	int number = rand() % 6 + Number;
	//随机敌机位置
	for (int i = 0; i < number; i++)
	{
		short x = rand() % (width - 4) + 2;
		//防止敌机重叠
		if (enemyArr[x][2] == '+' || enemyArr[x - 1][2] == '+' || enemyArr[x + 1][2] == '+' || enemyArr[x - 2][2] == '+' || enemyArr[x + 2][2] == '+')
			continue;
		short y = 2;
		enemyArr[x][y] = '+';
		enemyArr[x][y - 1] = 'T';
		enemyArr[x - 1][y - 1] = 'q';
		enemyArr[x + 1][y - 1] = 'p';
 
		gotoxy(x, y);
		cout << "+";//头
		gotoxy(x, y - 1);
		cout << "T";//尾   
		gotoxy(x - 1, y - 1);
		cout << "q";//右翼     //+++ 
		gotoxy(x + 1, y - 1);  // 0   
		cout << "p";//左翼
 
	}
}
 
void enemyMove(char enemyArr[width + 10][height])
{
	for (int i = width; i > 0; i--)
		for (int j = height - 3; j > 0; j--)
		{
			if (enemyArr[i][j] == '+')
			{
				enemyArr[i][j - 1] = 0;
				enemyArr[i - 1][j - 1] = 0;
				enemyArr[i + 1][j - 1] = 0;
 
				enemyArr[i][j] = 'T';
				enemyArr[i][j + 1] = '+';
				enemyArr[i - 1][j] = 'q';
				enemyArr[i + 1][j] = 'p';
				gotoxy(i, j - 1);
				cout << " ";
				gotoxy(i - 1, j - 1);
				cout << " ";
				gotoxy(i + 1, j - 1);
				cout << " ";
				gotoxy(i, j + 1);
				cout << "+";
				gotoxy(i, j);
				cout << "T";
				gotoxy(i - 1, j);
				cout << "q";
				gotoxy(i + 1, j);
				cout << "p";
			}
		}
 
	//清除触界敌机
	for (int i = 0; i < width; i++)
	{
		if (enemyArr[i][height - 2] == '+')
		{
			enemyArr[i][height - 2] = 0;
			enemyArr[i][height - 3] = 0;
			enemyArr[i + 1][height - 3] = 0;
			enemyArr[i - 1][height - 3] = 0;
			gotoxy(i, height - 2);
			cout << " ";
			gotoxy(i - 1, height - 3);
			cout << " ";
			gotoxy(i + 1, height - 3);
			cout << " ";
			gotoxy(i, height - 3);
			cout << " ";
			score++;
		}
	}
}
 
//判断是否触碰敌机
bool judgeEnemy(short x, short y, char enemyArr[width + 10][height])
{
	if (enemyArr[x][y] == '+' || enemyArr[x][y] == 'p' || enemyArr[x][y] == 'q' || enemyArr[x - 1][y + 1] == '+' || enemyArr[x - 1][y + 1] == 'p' || enemyArr[x - 1][y + 1] == 'q'
		|| enemyArr[x + 1][y + 1] == '+' || enemyArr[x + 1][y + 1] == 'p' || enemyArr[x + 1][y + 1] == 'q' || enemyArr[x][y + 1] == '+' || enemyArr[x][y + 1] == 'p' || enemyArr[x][y + 1] == 'q')
	{
		return true;
	}
	else
	{
 
		gotoxy(width + (t_width - width) / 2, 11);
		cout << HP << "    ";
		return false;
	}
}

函数整合:

void Game()
{
	//存储敌机坐标
	system("cls");
	difficulty();
	system("cls");
	cartoonStartMenu();
	game_menu();
	p.initMyPlane();
	while (true)
	{
		enemyAppear(enemyArr);
        //这里可能有点难理解,可以先把外层循环去掉只看内层循环
        //Sleep(1)是停止1ms也就是说每enemySpeed毫秒子弹,敌军移动一次
        //把外层循环加进来就是10*enemySpeed毫秒敌军出现一次
        //这样写的目的是使得每一毫秒程序都能检测是否有按键移动射击操作
		for (int i = 0; i < 10; i++)
		{
 
			for (int j = 0; j < enemySpeed; j++) {
				p.myPlaneMove(enemyArr);
				if (judgeEnemy(p.x, p.y, enemyArr))
				{
					end_menu();
				}
				Sleep(1);
			}
			bulletMove(myBulletArr);
			shotEnemy(enemyArr, myBulletArr);
			enemyMove(enemyArr);
			gotoxy(width + (t_width - width) / 2, 7);
			cout << score;
            //分数大于200进入BOSS战
			if (score > 200)
				BOSSgame();
		}
	}
 
}

BOSS功能的实现:

大家在这里可以充分发挥自己的创造力啊>_<

//BOSS子弹移动
void enemyBulletMove(char enemyArr[width + 10][height])
{
	for (int i = width; i > 0; i--)
		for (int j = height - 3; j > 0; j--)
		{
			if (enemyArr[i][j] == '+')
			{
				enemyArr[i][j] = 0;
				enemyArr[i][j + 1] = '+';
 
				gotoxy(i, j);
				cout << " ";
 
				gotoxy(i, j + 1);
				cout << "+";
				judgeBOSSBullet(p.x, p.y, enemyArr);
			}
		}
 
	//清除触界敌军子弹
	for (int i = 0; i < width; i++)
	{
		if (enemyArr[i][height - 2] == '+')
		{
			enemyArr[i][height - 2] = 0;
 
			gotoxy(i, height - 2);
			cout << " ";
		}
	}
}
 
 
//持续射击
void keepShooting(char enemyArr[width + 10][height])
{
	srand((unsigned int)time(NULL));
	for (int j = 0; j < 100; j++)
	{
		int x = rand() % 78 + 1;
		gotoxy(x, 16);
		cout << "+";
		enemyArr[x][16] = '+';
		gotoxy(79 - x, 16);
		cout << "+";
		enemyArr[79 - x][16] = '+';
		for (int j = 0; j < BOSSspeed; j++)
		{
			Sleep(1);
			p.myPlaneMove(enemyArr);
		}
		enemyBulletMove(enemyArr);
		bulletMove(myBulletArr);
		shotBOSS(myBulletArr);
	}
}
 
 
//技能1
void skillA(char enemyArr[width + 10][height])
{
	srand((unsigned int)time(NULL));
	for (int z = 0; z < 3; z++)
	{
		for (int i = width / 2 - 5; i > 2; i--)
		{
			gotoxy(i, 16);
			cout << "+";
			enemyArr[i][16] = '+';
			gotoxy((width - i - 1), 16);
			cout << "+";
			enemyArr[width - i - 1][16] = '+';
			for (int j = 0; j < BOSSspeed; j++)
			{
				Sleep(1);
				p.myPlaneMove(enemyArr);
			}
			enemyBulletMove(enemyArr);
			bulletMove(myBulletArr);
			shotBOSS(myBulletArr);
		}
	}
 
}
 
 
//技能2
void skillB(char enemyArr[width + 10][height])
{
	srand((unsigned int)time(NULL));
	for (int z = 0; z < 3; z++)
	{
		int x = rand() % 76 + 2;
		gotoxy(x, 16);
		cout << "!";
		gotoxy(79 - x, 16);
		cout << "!";
		for (int k = 0; k < 10; k++)
		{
			for (int j = 0; j < BOSSspeed; j++)
			{
				Sleep(1);
				p.myPlaneMove(enemyArr);
			}
			enemyBulletMove(enemyArr);
			bulletMove(myBulletArr);
			shotBOSS(myBulletArr);
		}
		for (int i = 16; i < height - 1; i++)
		{
			gotoxy(x, i);
			cout << "+";
			enemyArr[x][i] = '+';
			gotoxy(x + 1, i);
			cout << "+";
			enemyArr[x + 1][i] = '+';
			gotoxy(x - 1, i);
			cout << "+";
			enemyArr[x - 1][i] = '+';
			gotoxy(79 - x, i);
			cout << "+";
			enemyArr[79 - x][i] = '+';
			gotoxy(79 - x - 1, i);
			cout << "+";
			enemyArr[79 - x - 1][i] = '+';
			gotoxy(79 - x + 1, i);
			cout << "+";
			enemyArr[79 - x + 1][i] = '+';
		}
	}
}
 
//技能3
void skillC(char enemyArr[width + 10][height])
{
	srand((unsigned int)time(NULL));
	int x = rand() % 6 + 37;
	gotoxy(x, 16);
	cout << "+";
	enemyArr[x][16] = '+';
	gotoxy(79 - x, 16);
	cout << "+";
	enemyArr[79 - x][16] = '+';
	p.myPlaneMove(enemyArr);
	enemyBulletMove(enemyArr);
	bulletMove(myBulletArr);
	shotBOSS(myBulletArr);
	for (int j = 0; j < 50; j++)
	{
		int dir = rand() % 2 - 1;
		x = x + dir;
		gotoxy(x, 16);
		cout << "+";
		enemyArr[x][16] = '+';
		gotoxy(79 - x, 16);
		cout << "+";
		enemyArr[79 - x][16] = '+';
		for (int j = 0; j < BOSSspeed; j++)
		{
			Sleep(1);
			p.myPlaneMove(enemyArr);
		}
		enemyBulletMove(enemyArr);
		bulletMove(myBulletArr);
		shotBOSS(myBulletArr);
	}
}
 
 
//BOSS血条
void BOSSHPcartoon()
{
	gotoxy(13, 1);
	cout << "HP:";
	gotoxy(16, 1);
	for (int i = 0; i < BOSSHP / 10; i++)
		cout << "▇";
	cout << "    ";
}
 
//射击BOSS检测
void shotBOSS(char myArr[width + 10][height])
{
	//尾部
	for (int i = 9; i < 14; i++)
	{
		if (myArr[i][4] == '*')
		{
			BOSSHP = BOSSHP - damage / 2;
			myArr[i][4] = 0;
			gotoxy(i, 4);
			cout << " ";
		}
		if (myArr[79 - i][4] == '*')
		{
			BOSSHP = BOSSHP - damage / 2;
			myArr[79 - i][4] = 0;
			gotoxy(79 - i, 4);
			cout << " ";
		}
	}
	//中后部
	for (int i = 14; i < 18; i++)
	{
		if (myArr[i][6] == '*')
		{
			BOSSHP = BOSSHP - damage;
			myArr[i][6] = 0;
			gotoxy(i, 6);
			cout << " ";
		}
		if (myArr[79 - i][6] == '*')
		{
			BOSSHP = BOSSHP - damage;
			myArr[79 - i][6] = 0;
			gotoxy(79 - i, 6);
			cout << " ";
		}
	}
	//中前部
	for (int i = 18; i < 29; i++)
	{
		if (myArr[i][11] == '*')
		{
			BOSSHP = BOSSHP - damage;
			myArr[i][11] = 0;
			gotoxy(i, 11);
			cout << " ";
		}
		if (myArr[79 - i][11] == '*')
		{
			BOSSHP = BOSSHP - damage;
			myArr[79 - i][11] = 0;
			gotoxy(79 - i, 11);
			cout << " ";
		}
	}
	for (int i = 27; i < 40; i++)
	{
		if (myArr[i][13] == '*')
		{
			BOSSHP = BOSSHP - damage;
			myArr[i][13] = 0;
			gotoxy(i, 13);
			cout << " ";
		}
		if (myArr[79 - i][13] == '*')
		{
			BOSSHP = BOSSHP - damage;
			myArr[79 - i][13] = 0;
			gotoxy(79 - i, 13);
			cout << " ";
		}
	}
	//头后部
	for (int i = 31; i < 40; i++)
	{
		if (myArr[i][15] == '*')
		{
			BOSSHP = BOSSHP - 2 * damage;
			myArr[i][15] = 0;
			gotoxy(i, 15);
			cout << " ";
		}
		if (myArr[79 - i][15] == '*')
		{
			BOSSHP = BOSSHP - 2 * damage;
			myArr[79 - i][15] = 0;
			gotoxy(79 - i, 15);
			cout << " ";
		}
	}
	//头部
	for (int i = 37; i < 40; i++)
	{
		if (myArr[i][16] == '*')
		{
			BOSSHP = BOSSHP - 2 * damage;
			myArr[i][16] = 0;
			gotoxy(i, 16);
			cout << " ";
		}
		if (myArr[79 - i][16] == '*')
		{
			BOSSHP = BOSSHP - 2 * damage;
			myArr[79 - i][16] = 0;
			gotoxy(79 - i, 16);
			cout << " ";
		}
	}
	BOSSHPcartoon();
	if (BOSSHP <= 0)
		success_menu();
}
 
 
void BOSSshot(char enemyArr[width + 10][height])
{
	srand((unsigned int)time(NULL));
	while (true)
	{
		int i = rand() % 4;
		switch (i)
		{
		case 0:
			keepShooting(enemyArr);
			break;
		case 1:
			skillA(enemyArr);
			break;
		case 2:
			skillB(enemyArr);
			break;
		case 3:
			skillC(enemyArr);
			break;
		}
	}
}

BOSS函数整合:

void BOSSgame()
{
	BOSS = 1;
	bullet = 1000;
	for (int i = 2; i < width; i++)
		for (int j = 2; j < height; j++)
		{
			if (enemyArr[i][j] == '+')
			{
				enemyArr[i][j] = 0;
				enemyArr[i - 1][j - 1] = 0;
				enemyArr[i + 1][j - 1] = 0;
				enemyArr[i][j - 1] = 0;
 
 
				gotoxy(i - 1, j - 1);
				cout << " ";
				gotoxy(i + 1, j - 1);
				cout << " ";
				gotoxy(i, j - 1);
				cout << " ";
				gotoxy(i, j);
				cout << " ";
			}
		}
 
	BOSScartoon();
	BOSSHPcartoon();
	BOSSshot(enemyArr);
}

菜单,动画的实现:

这个动画。。。嘿嘿,其实没啥学的必要,我是图省事这么写的,你们肯定有更好的办法来实现

大家看看上面的菜单就行了,可以直接看后面的main函数

//开始菜单
void start_menu()
{
	for (int i = t_height - 1; i >= t_height / 2 - 4; i--)
	{
		gotoxy(t_width / 2 - 5, i + 1);
		cout << "        ";
		gotoxy(t_width / 2 - 5, i);
		cout << "飞机大战";
		if (i < t_height - 2 - 4)
		{
			gotoxy(t_width / 2 - 6, i + 5);
			cout << "          ";
			gotoxy(t_width / 2 - 6, i + 4);
			cout << "y.进入游戏";
 
		}
		if (i < t_height - 2 - 8)
		{
			gotoxy(t_width / 2 - 6, i + 9);
			cout << "          ";
			gotoxy(t_width / 2 - 6, i + 8);
			cout << "n.退出游戏";
		}
		Sleep(300);
	}
	while (true)
	{
		if (_kbhit())
		{
			char input = _getch();
 
 
			switch (input)
			{
			case 'n':
				system("cls");
				cout << "退出成功" << endl;
				exit(0);
				break;
			case 'N':
				system("cls");
				cout << "退出成功" << endl;
				exit(0);
				break;
			case 'y':
				system("cls");
				cout << "进入游戏" << endl;
				Sleep(1000);
				system("cls");
				Game();
 
				break;
			
			case 'Y':
				system("cls");
				cout << "进入游戏" << endl;
				Sleep(1000);
				system("cls");
				Game();
 
				break;
			}
		}
		
	}
}
 
void cartoonStartMenu()
{
 
	gotoxy(t_width / 2 - 8, t_height / 2 - 6);
	cout << "************";
	gotoxy(t_width / 2 - 8, t_height / 2 - 5);
	cout << "           *";
	gotoxy(t_width / 2 - 8, t_height / 2 - 4);
	cout << "           *";
	gotoxy(t_width / 2 - 8, t_height / 2 - 3);
	cout << "           *";
	gotoxy(t_width / 2 - 8, t_height / 2 - 2);
	cout << "************";
	gotoxy(t_width / 2 - 8, t_height / 2 - 1);
	cout << "           *";
	gotoxy(t_width / 2 - 8, t_height / 2);
	cout << "           *";
	gotoxy(t_width / 2 - 8, t_height / 2 + 1);
	cout << "           *";
	gotoxy(t_width / 2 - 8, t_height / 2 + 2);
	cout << "************";
	Sleep(1000);
	system("cls");
	gotoxy(t_width / 2 - 8, t_height / 2 - 6);
	cout << "************";
	gotoxy(t_width / 2 - 8, t_height / 2 - 5);
	cout << "           *";
	gotoxy(t_width / 2 - 8, t_height / 2 - 4);
	cout << "           *";
	gotoxy(t_width / 2 - 8, t_height / 2 - 3);
	cout << "           *";
	gotoxy(t_width / 2 - 8, t_height / 2 - 2);
	cout << "************";
	gotoxy(t_width / 2 - 8, t_height / 2 - 1);
	cout << "*           ";
	gotoxy(t_width / 2 - 8, t_height / 2);
	cout << "*           ";
	gotoxy(t_width / 2 - 8, t_height / 2 + 1);
	cout << "*           ";
	gotoxy(t_width / 2 - 8, t_height / 2 + 2);
	cout << "************";
	Sleep(1000);
	system("cls");
	gotoxy(t_width / 2 - 8, t_height / 2 - 6);
	cout << "     **     ";
	gotoxy(t_width / 2 - 8, t_height / 2 - 5);
	cout << "     **     ";
	gotoxy(t_width / 2 - 8, t_height / 2 - 4);
	cout << "     **     ";
	gotoxy(t_width / 2 - 8, t_height / 2 - 3);
	cout << "     **     ";
	gotoxy(t_width / 2 - 8, t_height / 2 - 2);
	cout << "     **     ";
	gotoxy(t_width / 2 - 8, t_height / 2 - 1);
	cout << "     **     ";
	gotoxy(t_width / 2 - 8, t_height / 2);
	cout << "     **     ";
	gotoxy(t_width / 2 - 8, t_height / 2 + 1);
	cout << "     **     ";
	gotoxy(t_width / 2 - 8, t_height / 2 + 2);
	cout << "     **     ";
	Sleep(1000);
	system("cls");
}
 
 
//地图框架和右菜单
void game_menu()
{
	//框架
	gotoxy(0, 0);
	for (int i = 0; i < width; i++)
		cout << "#";
	gotoxy(0, height - 1);
	for (int i = 0; i < width; i++)
		cout << "#";
	for (int i = 0; i < height; i++)
	{
		gotoxy(0, i);
		cout << "#";
	}
	for (int i = 0; i < height; i++)
	{
		gotoxy(width - 1, i);
		cout << "#";
	}
 
 
	//右部菜单
	gotoxy(width + (t_width - width) / 2 - 6, 5);
	cout << "代号:NJTECH";
	gotoxy(width + (t_width - width) / 2 - 6, 7);
	cout << "得分:";
	gotoxy(width + (t_width - width) / 2 - 6, 9);
	cout << "子弹:";
	gotoxy(width + (t_width - width) / 2 - 6, 11);
	cout << "血量:";
 
	gotoxy(width, 13);
	cout << "                   **                   ";
	gotoxy(width, 14);
	cout << "                   **                   ";
	gotoxy(width, 15);
	cout << "                   **                   ";
	gotoxy(width, 16);
	cout << "                  ****                  ";
	gotoxy(width, 17);
	cout << "                 ******                 ";
	gotoxy(width, 18);
	cout << "            *  ****  ****  *            ";
	gotoxy(width, 19);
	cout << "           ******************           ";
	gotoxy(width, 20);
	cout << "          ****   ******   ****          ";
	gotoxy(width, 21);
	cout << "       **************************       ";
	gotoxy(width, 22);
	cout << "             ****      ****             ";
	gotoxy(width, 23);
	cout << "               **      **               ";
	gotoxy(width, 24);
	cout << "                *      *                ";
	//规则
	gotoxy(width + (t_width - width) / 2 - 14, 28);
	cout << "w 前进";
	gotoxy(width + (t_width - width) / 2 - 14, 30);
	cout << "s 后退";
	gotoxy(width + (t_width - width) / 2 - 14, 32);
	cout << "d 右移";
	gotoxy(width + (t_width - width) / 2 - 14, 34);
	cout << "a 左移";
	gotoxy(width + (t_width - width) / 2 - 14, 36);
	cout << "j 射击";
}
 
 
 
void cartoonGameMenu()
{
	for (int i = 0; i < height / 2; i++)
	{
		gotoxy(0, i);
		for (int j = 0; j < t_width; j++)
		{
			cout << "▇";
		}
		gotoxy(0, height - i - 1);
		for (int k = 0; k < t_width; k++)
		{
			cout << "▇";
		}
		Sleep(100);
	}
	system("cls");
	Sleep(1000);
	for (int i = 0; i < t_width; i++)
	{
		for (int j = 0; j < t_height; j++)
		{
			cout << "▇";
			if (j == t_width - 1)
				cout << endl;
		}
	}
	Sleep(1000);
	system("cls");
	Sleep(1000);
 
}
 
void BOSScartoon()
{
	for (int i = 0; i < 9; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 - 8 + i);
		cout << "****";
	}
	for (int i = 0; i < 3; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 + 2 + i);
		cout << "****";
	}
	Sleep(1000);
	for (int i = 0; i < 9; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 - 8 + i);
		cout << "    ";
	}
	for (int i = 0; i < 3; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 + 2 + i);
		cout << "    ";
	}
	Sleep(1000);
	for (int i = 0; i < 9; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 - 8 + i);
		cout << "****";
	}
	for (int i = 0; i < 3; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 + 2 + i);
		cout << "****";
	}
	Sleep(1000);
	for (int i = 0; i < 9; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 - 8 + i);
		cout << "    ";
	}
	for (int i = 0; i < 3; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 + 2 + i);
		cout << "    ";
	}
	Sleep(1000);
	for (int i = 0; i < 9; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 - 8 + i);
		cout << "****";
	}
	for (int i = 0; i < 3; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 + 2 + i);
		cout << "****";
	}
	Sleep(1000);
	for (int i = 0; i < 9; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 - 8 + i);
		cout << "    ";
	}
	for (int i = 0; i < 3; i++)
	{
		gotoxy(width / 2 - 1, t_height / 2 + 2 + i);
		cout << "    ";
	}
	Sleep(1000);
	printBOSS();
}
 
void end_menu()
{
	system("cls");
	Sleep(3000);
	gotoxy(width / 2 - 8, height - 1);
	cout << "你失败了,但这不是你的过错,只是这次的英雄并不是你......";
	Sleep(300);
	for (int i = height - 2; i > 18; i--)
	{
		gotoxy(width / 2 - 8, i + 1);
		cout << "                                                        ";
		gotoxy(width / 2 - 8, i);
		cout << "你失败了,但这不是你的过错,只是这次的英雄并不是你......";
		Sleep(300);
	}
	
	Sleep(10000000);
}
 
void success_menu()
{
	for (int i = 16; i > 1; i--)
	{
		gotoxy(2, i);
		cout << "                                                                     ";
		Sleep(100);
	}
	Sleep(1000);
	gotoxy(width / 2 - 3, 2);
	cout << "游戏胜利";
	Sleep(300);
	for (int i = 3; i < 17; i++)
	{
		gotoxy(width / 2 - 3, i - 1);
		cout << "        ";
		gotoxy(width / 2 - 3, i);
		cout << "游戏胜利";
		Sleep(300);
	}
	Sleep(100000);
}
 
void printBOSS()
{
	gotoxy(0, 0);
	for (int i = 0; i < width; i++)
		cout << "#";
	gotoxy(0, height - 1);
	for (int i = 0; i < width; i++)
		cout << "#";
	for (int i = 0; i < height; i++)
	{
		gotoxy(0, i);
		cout << "#";
	}
	for (int i = 0; i < height; i++)
	{
		gotoxy(width - 1, i);
		cout << "#";
	}
	for (int i = 2; i < 16; i++)
	{
		gotoxy(37, i);
		cout << "\\ ++ /";
		if (i > 2)
		{
			gotoxy(33, i - 1);
			cout << "\\  \\  ++  /  /";
 
		}
		if (i > 3)
		{
			gotoxy(30, i - 2);
			cout << "\\ \\  \\   ++   /  / /";
		}
		if (i > 4)
		{
			gotoxy(27, i - 3);
			cout << "+++++++************+++++++";
			gotoxy(27, i - 4);
			cout << "                          ";
		}
		if (i > 5)
		{
			gotoxy(32, i - 4);
			cout << "****************";
			gotoxy(32, i - 5);
			cout << "                ";
		}
		if (i > 6)
		{
			gotoxy(18, i - 5);
			cout << "***  ***00******   ******   ******00***  ***";
			gotoxy(18, i - 6);
			cout << "                                            ";
		}
		if (i > 7)
		{
			gotoxy(19, i - 6);
			cout << "******00****   **  ****  **   ****00******";
			gotoxy(19, i - 7);
			cout << "                                          ";
		}
		if (i > 8)
		{
			gotoxy(24, i - 7);
			cout << "*****    *00*      *00*    *****";
			gotoxy(24, i - 8);
			cout << "                                ";
		}
		if (i > 9)
		{
			gotoxy(22, i - 8);
			cout << "****   ****0000* ** *0000****   ****";
			gotoxy(22, i - 9);
			cout << "                                    ";
		}
		if (i > 10)
		{
			gotoxy(23, i - 9);
			cout << "*********0000***  ***0000*********";
			gotoxy(23, i - 10);
			cout << "                                  ";
		}
		if (i > 11)
		{
			gotoxy(14, i - 10);
			cout << "*********** ************    ************ ***********";
			gotoxy(14, i - 11);
			cout << "                                                    ";
		}
		if (i > 12)
		{
			gotoxy(14, i - 11);
			cout << "********   ***  *  *  *      *  *  *  ***   ********";
			gotoxy(14, i - 12);
			cout << "                                                    ";
		}
		if (i > 13)
		{
			gotoxy(9, i - 12);
			cout << "************       ******    ****    ******       ************";
			gotoxy(9, i - 13);
			cout << "                                                              ";
		}
		Sleep(300);
	}
 
 
 
}

main函数实现:

int main()
{
	system("mode con cols=120 lines=40");
	clearCursor();
	cartoonGameMenu();
	start_menu();
	cartoonStartMenu();
	game_menu();
	BOSSgame();
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/548939.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

OAuth2.0 OIDC1.0及落地方案

目录 一、导语二、初识OAuth2.0三、OAuth2.0四、OIDC1.0五、OAuth2.0 & OIDC1.0授权模式选型建议六、典型架构及示例6.1 用户认证中心6.2 客户端6.3 应用网关6.4 后端API服务 七、附录- OAuth & OIDC常用端点 一、导语 应用的使用离不开用户&#xff0c;所以用户认证与…

缓存架构设计Spring对于Cache的抽象架构

目录 缓存架构设计 JSR107 JSR107核心接口 JSR107图示 Spring对于Cache的抽象架构 介绍 Cacheable CachePut CacheEvict CacheConfig 缓存架构设计 JSR107 首先&#xff0c;来了解一下JSR107规范JSR是Java Specification Requests 的缩写 &#xff0c;Java规范请求&…

chatgpt赋能Python-python3_ljust

Python 3 ljust - 实现字符串长度对齐的神器 在Python 3中&#xff0c;ljust()是一个非常常用的字符串方法。它可以方便地对齐字符串&#xff0c;并添加左对齐的填充字符。无疑&#xff0c;它是Python编程中不可缺少且十分实用的工具神器。 什么是ljust()&#xff1f; ljust…

MybatisPlus数据层标准的CRUD(增删改查)的实现与分页功能

文章目录 1 标准CRUD使用2 新增3 删除4 修改5 根据ID查询6 查询所有7 Lombok步骤1:添加lombok依赖步骤2:安装Lombok的插件步骤3:模型类上添加注解 8 分页功能步骤1:调用方法传入参数获取返回值步骤2:设置分页拦截器步骤3:运行测试程序 在这一节中我们重点学习的是数据层标准的C…

每日练习---C语言

目录 前言&#xff1a; 1.打印菱形 1.1补充练习 2.打印水仙花 2.1补充训练 前言&#xff1a; 记录博主做题的收获&#xff0c;以及提升自己的代码能力&#xff0c;今天写的题目是&#xff1a;打印菱形、打印水仙花数。 1.打印菱形 我们先看到牛客网的题&#xff1a;OJ链…

利用ChatGPT编写Excel公式,对比讯飞星火与ChatGPT对Excel公式的回答

系列文章目录 借助国内ChatGPT平替MindShow&#xff0c;飞速制作PPT 借助国内ChatGPT平替markmap/Xmind飞速生成思维导图 借助国内ChatGPT平替剪映/百度AIGC平台快速制作短视频 文章目录 系列文章目录前言一、利用ChatGPT编写Excel公式1.描述我们想实现的Excel公式&#xff…

四、医院模块开发

文章目录 一、医院模块开发1、搭建医院模块service-hosp1.1搭建service-hosp1.2修改配置1.3 添加启动类 2、添加医院设置CURD2.1 添加model2.2 添加Mapper2.3 添加service接口及实现类2.4 添加controller2.5 医院设置CRUD2.6 添加controller方法 3、Swagger2介绍与集成4、医院锁…

【Python beautiful soup】如何用beautiful soup 解析HTML内容

美丽汤&#xff08;Beautiful Soup&#xff09;是一个流行的Python库&#xff0c;用于从HTML或XML文件中提取数据。它将复杂的HTML文件转化为一个Python对象&#xff0c;使得用户可以更方便地解析、搜索和修改HTML内容。本文将介绍如何使用Beautiful Soup解析HTML内容&#xff…

数据的家——MySQL的数据目录

之前学过了行格式&#xff0c;在往上面是页&#xff0c;最上层的也就学到了页。 现在的数据目录是什么&#xff1f;这之间有什么关系呢&#xff1f;带着这个问题&#xff0c;来继续学习。 数据库和文件系统的关系是什么&#xff1f; InnoDB和MyISAMy 是把表存储在磁盘上面的…

【计算机网络之HTTP篇】HTTPS与HTTP的区别

目录 HTTPS产生的原因 HTTPS工作原理 对称加密 非对称加密 引入数字证书 HTTPS完整工作流程 高频面试题&#xff1a;HTTPS与HTTP的区别 HTTPS产生的原因 HTTP协议是按照文本的形式来明文传递数据的&#xff0c;因此数据很容易被黑客劫持&#xff0c;发生泄密可能。 HTTP…

AlmaLinux 8.8 发布 - RHEL 下游免费发行版(CentOS 稳定版的替代品)

AlmaLinux 8.8 发布 - RHEL 下游免费发行版&#xff08;CentOS 稳定版的替代品&#xff09; AlmaLinux OS 是一个开源、社区驱动的项目&#xff0c;旨在提供 CentOS 稳定版的替代品。 请访问原文链接&#xff1a;https://sysin.org/blog/almalinux-8/&#xff0c;查看最新版。…

Linux系统编程——多线程[补充]:懒汉模式自旋锁读者写者问题

0.关注博主有更多知识 操作系统入门知识合集 目录 1.单例设计模式 1.1将线程池设计为懒汉方式实现的单例模式 1.2线程安全版本的懒汉方式 2.STL、智能指针与线程安全 3.自旋锁 4.读者写者问题 1.单例设计模式 在一些软件设计场景当中&#xff0c;要求某些类只能具有一…

五一后“实在高校行”紧锣密鼓走进四所高校,校企合作硕果累累!

近年来&#xff0c;随着人工智能科技的快速发展&#xff0c;越来越多高校加快了与先进企业在培养优秀人才的合作步伐。实在智能一直注重校园生态发展及在人才培养&#xff0c;不断引进数字化人才&#xff0c;做强培训师资&#xff1b;同时积极走出去&#xff0c;在全社会范围内…

2023-05-20:go语言的slice和rust语言的Vec的扩容流程是什么?

2023-05-20&#xff1a;go语言的slice和rust语言的Vec的扩容流程是什么&#xff1f; 答案2023-05-20&#xff1a; go语言的slice扩容流程 go版本是1.20.4。 扩容流程见源码见runtime/slice.go文件中的growslice 函数。 growslice 函数的大致过程如下&#xff1a; 1.如果元…

Mybatis Plus之DQL(条件查询方式、查询投影、查询条件设定、字段映射与表名映射)

文章目录 1 条件查询1.1 条件查询的类1.2 环境构建1.3 构建条件查询1.4 多条件构建1.5 null判定 2 查询投影2.1 查询指定字段2.2 聚合查询2.3 分组查询 3 查询条件3.1 等值查询3.2 范围查询3.3 模糊查询3.4 排序查询 4 映射匹配兼容性问题1:表字段与编码属性设计不同步问题2:编…

你真的知道怎么使用vs吗?把把手教你实用调试小技巧

实用调试小技巧 1.什么是bug&#xff1f;2.调试是什么&#xff1f;有多重要&#xff1f;3.debug和release的介绍。4.windows环境调试介绍。4.1常见调试快捷键4.2 调试的时候查看程序当前信息4.2.1监视&#xff1a;4.2.2内存4.2.3调用堆栈4.2.4反汇编4.2.5寄存器 5.一些调试的实…

HNU-计算机系统-实验4-ShellLab

ShellLab 计科2102 梅炳寅 202108010206 写在前面 作为一份实验报告,我希望阅读者能够比较好地看到这份报告有价值的部分。私以为更为有价值的部分体现在: 报告中打★的部分,最后的代码中,我在代码中加入了大量的中文注释、函数原型、参数解读、以及个人对代码的推断与理…

网易云音乐开发--音乐播放暂停切换上下首功能实现

音乐播放暂停功能实现 封装一个控制音乐播放/暂停的功能函数 看一下文档&#xff0c;我需要用的api 这个接口好像没有音频的url&#xff0c;查看一下&#xff0c;换个api 这样就能拿到id&#xff0c;并可以播放了 但是音乐并没有播放 我们少了这个 现在可以播放了&#xff…

[CTF/网络安全] 攻防世界 view_source 解题详析

[CTF/网络安全] 攻防世界 view_source 解题详析 查看页面源代码方式归类总结 题目描述&#xff1a;X老师让小宁同学查看一个网页的源代码&#xff0c;但小宁同学发现鼠标右键好像不管用了。 查看页面源代码方式归类 单击鼠标右键&#xff0c;点击查看页面源代码&#xff1a; …

Linux 指令(三)+完整思维导图+实图例子+深入细节+通俗易懂建议收藏

绪论 涓滴之水终可磨损大石&#xff0c;不是由于它的力量强大&#xff0c;而是由于昼夜不舍的滴坠。今天我们继续学习Linux指令。 话不多说安全带系好&#xff0c;发车啦&#xff08;建议电脑观看&#xff09;。 附&#xff1a;红色&#xff0c;部分为重点部分&#xff1b;蓝颜…