這個程式的原始碼沒有什么技術要求,一般至少能看懂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語言實作字符界面貪吃蛇
