主頁 >  其他 > 無任何格外需求的命令列C++飛機大戰,內含BOSS,影片,千行代碼免費奉上

無任何格外需求的命令列C++飛機大戰,內含BOSS,影片,千行代碼免費奉上

2021-12-31 07:55:15 其他

這個程式的原始碼沒有什么技術要求,一般至少能看懂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();
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/398516.html

標籤:其他

上一篇:C語言實作字符界面貪吃蛇

下一篇:C++一個基于Qt開發的 *斗*地*主*小游戲原始碼

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more