用二维数组来控制移动,变量x和y表示坐标。
还有发炮方向,由上一个方向发炮。
(没有那些3D2D图像,也没有那么牛的发炮特效,单纯的是一个文本移动游戏)
wsad控制,在最后一关,r键拆弹,Space(空格)键发炮。
在最后的一关,|是墙壁,%是炸弹。
地图中,$和&是敌人(不能移动)。
#是你。
地图上随机出现的.是敌方随机地雷,每关2条命,最后一关命增加。
MUBIAO是每关的终点,但需要打掉要求的敌人才能通过。
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <windows.h>
#include <ctime>
using namespace std;
void cpp1()
{
int xueliang = 2;
long long diren = 4;
int x=0, y=0;
string see;
char map1[10][20] =
{
"******MUBIAO*******",
"**&************&***",
"*****$******$******",
"*******************",
"*******************",
"*******************",
"*******************",
"*******************",
"*******************",
"*******************"
};
map1[x][y] = '#';
char ch;
int o, q;
for (; true;)
{
system("cls");
for(; true;)
{
o = rand() % 9;
q = rand() % 19;
if (map1[o][q] != '#' &&map1[o][q]!='*')
continue;
map1[o][q] = '.';
break;
}
for (int j = 0; j < 10; j++)
{
cout << endl;
for (int i = 0; i < 20; i++)
cout << map1[j][i];
}
if (map1[o][q] == '#')
xueliang--;
if (xueliang <= 0)
{
cout << "GAME OVER!" << endl;
break;
}
cout << endl;
ch = _getch();
if (map1[x - 1][y] == 'M' || map1[x - 1][y] == 'U' || map1[x - 1][y] == 'B' || map1[x - 1][y] == 'I' || map1[x - 1][y] == 'A' || map1[x - 1][y] == 'O')
{
if (diren <= 0 && ch == 'w')
{
cout << "GOOD JOB!" << endl;
Sleep(1000);
break;
}
}
if (map1[x + 1][y] == 'M' || map1[x + 1][y] == 'U' || map1[x + 1][y] == 'B' || map1[x + 1][y] == 'I' || map1[x + 1][y] == 'A' || map1[x + 1][y] == 'O')
{
if (diren <= 0 && ch == 's')
{
cout << "GOOD JOB!" << endl;
Sleep(1000);
break;
}
}
if (map1[x][y - 1] == 'M' || map1[x][y - 1] == 'U' || map1[x][y - 1] == 'B' || map1[x][y - 1] == 'I' || map1[x][y - 1] == 'A' || map1[x][y - 1] == 'O')
{
if (diren <= 0 && ch == 'a')
{
cout << "GOOD JOB!" << endl;
Sleep(1000);
break;
}
}
if (map1[x][y + 1] == 'M' || map1[x][y + 1] == 'U' || map1[x][y + 1] == 'B' || map1[x][y + 1] == 'I' || map1[x][y + 1] == 'A' || map1[x][y + 1] == 'O')
{
if (diren <= 0 && ch == 'd')
{
cout << "GOOD JOB!" << endl;
Sleep(1000);
break;
}
}
if (ch == 'w' && map1[x - 1][y] == '*')
{
map1[x][y] = '*';
x--;
map1[x][y] = '#';
see = "up";
}
if (ch == 's' && map1[x + 1][y] == '*')
{
map1[x][y] = '*';
x++;
map1[x][y] = '#';
see = "down";
}
if (ch == 'a' && map1[x][y - 1] == '*')
{
map1[x][y] = '*';
y--;
map1[x][y] = '#';
see = "left";
}
if (ch == 'd' && map1[x][y + 1] == '*')
{
map1[x][y] = '*';
y++;
map1[x][y] = '#';
see = "right";
}
if (ch == 32)
{
if (see == "up" || see == "down")
{
for (int i = 0; i < x; i++)
if (map1[i][y] == '$' || map1[i][y] == '&')
{
map1[i][y] = '*';
diren--;
break;
}
};
if (see == "left" || see == "right")
{
for (int i = 0; i < y; i++)
if (map1[x][i] == '$' || map1[x][i] ==