【改编】迷宫游戏2.0.1
调整:
1.增加并完善验证系统
2.换上了由PJL神仙制作的迷宫游戏2.0,请注意,该游戏会调整怪物、加血道具等的颜色。但是有些无法显示出来颜色,会
建议你更新系统,更新完毕后会是
该文章同步与:this
广告: c++游戏娱乐中心
#include<bits/stdc++.h>
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include<time.h>
#define RED(s) std::cout << RED << s << RESET;
#define GREEN(s) std::cout << GREEN << s << RESET;
#define YELLOW(s) std::cout << YELLOW << s << RESET;
#define BLUE(s) std::cout << BLUE << s << RESET;
#define qp system("CLS")
using namespace std;
void read(string a,int b)
{
for(int i=0;i<a.size();i++)
{
cout<<a[i];
Sleep(b);
}
}
const int MAXN = 1e2;
const std::string RED = "\033[31m"; // 红色
const std::string GREEN = "\033[32m"; // 绿色
const std::string YELLOW = "\033[33m"; // 黄色
const std::string BLUE = "\033[34m"; // 蓝色
const std::string RESET = "\033[0m"; // 重置颜色
void ys(int a) {
if (a == 0)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
if (a == 1)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
if (a == 2)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
if (a == 3)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);
if (a == 4)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
if (a == 5)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
if (a == 6)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
}
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
int len, x, y, Level = 1, hp = 3, CD = 0, ICD = 10, stop = 0, SCD = 30;
bool die = false;
char c[MAXN][MAXN];
void slowsay(int v, string s) {
for(int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(v);
}
return;
}
struct P {
int x, y, d;
}zd[MAXN];
void M() {
for(int i = 1; i <= len; i++) {
if(zd[i].d != -1) {
if(c[zd[i].x][zd[i].y] == '@') {
die = true;
return;
}
c[zd[i].x][zd[i].y] = '.';
zd[i].x += dx[zd[i].d], zd[i].y += dy[zd[i].d];
if(c[zd[i].x][zd[i].y] == '#' || c[zd[i].x][zd[i].y] == 'L' || c[zd[i].x][zd[i].y] == 'J') {
zd[i].d = -1;
}
else {
c[zd[i].x][zd[i].y] = 'Z';
if(x == zd[i].x && y == zd[i].y) {
die = true;
return;
}
}
}
}
if(CD % 3 == 0) {
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
if(c[i][j] == 'P') {
if(j == y && i > x && c[i - 1][j] != '#' && c[i - 1][j] != 'L' && c[i][j] != 'J') {
zd[++len] = {i - 1, j, 0};
c[zd[len].x][zd[len].y] = 'Z';
}
else if(j == y && i < x && c[i + 1][j] != '#' && c[i + 1][j] != 'L' && c[i][j] != 'J') {
zd[++len] = {i + 1, j, 1};
c[zd[len].x][zd[len].y] = 'Z';
}
else if(i == x && j > y && c[i][j - 1] != '#' && c[i][j - 1] != 'L' && c[i][j] != 'J') {
zd[++len] = {i, j - 1, 2};
c[zd[len].x][zd[len].y] = 'Z';
}
else if(i == x && j < y && c[i][j + 1] != '#' && c[i][j + 1] != 'L' && c[i][j] != 'J') {
zd[++len] = {i, j + 1, 3};
c[zd[len].x][zd[len].y] = 'Z';
}
}
}
}
}
}
void MAP() {
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
if(i == 1 || i == 20 || j == 1 || j == 20) {
c[i][j] = '#';
}
else {
int x = rand() % 40;
if(x <= 10) {
c[i][j] = '#';
}
else if(x >= 11 && x <= 37) {
c[i][j] = '.';
}
else if(x == 38) {
c[i][j] = 'P';
}
else {
c[i][j] = 'V';
}
}
}
}
c[2][2] = '@', c[19][19] = 'L';
}
void game(int p) {
Level = 1;
cout << "这个游戏是由PJL制作,并在迷宫游戏1.0上修改了一些的作品!\n";
cout << "这个作品叫\"迷宫游戏2.0\"!\n";
system("pause");
qp;
cout << "好了好了,废话不多说,开始游戏!";
Sleep(500);
qp;
a :
system("color 0F");
qp;
len = CD = stop = 0;
ICD = 10, SCD = 50;
if(hp <= 0) {
cout << "你的hp没有了!\n";
return;
}
if(Level == 11) {
ys(2);
slowsay(200, "你通过了所有关卡!!!\n\n");
ys(0);
int x = 30;
while(x) {
x--;
system("color 1A");Sleep(10);
system("color 2B");Sleep(10);
system("color 3C");Sleep(10);
system("color 4D");Sleep(10);
system("color 5D");Sleep(10);
system("color 6E");Sleep(10);
system("color 7F");Sleep(10);
}
system("color 0F");
return;
}
MAP();
x = 2, y = 2;
die = false;
while(1) {
SCD = max(SCD - 1, 0);
ICD = max(ICD - (stop == 0), 0);
cout << "第" << Level << "关\n";
cout << "HP : " << hp << "\n";
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
if(c[i][j] == 'P') {
YELLOW("P");
}
else if(c[i][j] == 'Z') {
RED("Z");
}
else if(c[i][j] == 'V') {
GREEN("V");
}
else if(c[i][j] == '@' && stop > 0) {
ys(rand() % 5 + 1);
cout << "@";
ys(0);
}
else {
cout << c[i][j];
}
}
cout << "\n";
}
if(c[x][y] == 'Z') {
hp--;
cout << "你死了!\n";
Sleep(2000);
goto a;
}
while(!kbhit()) {
}
char g = _getch();
if(g == 'Q') {
qp;
goto a;
}
else if(g == 'W' && c[x - 1][y] != '#') {
c[x][y] = '.';
x--;
}
else if(g == 'A' && c[x][y - 1] != '#') {
c[x][y] = '.';
y--;
}
else if(g == 'S' && c[x + 1][y] != '#') {
c[x][y] = '.';
x++;
}
else if(g == 'D' && c[x][y + 1] != '#') {
c[x][y] = '.';
y++;
}
if(c[x][y] == 'Z') {
qp;
cout << "第" << Level << "关\n";
cout << "HP : " << hp << "\n";
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
if(i == x && j == y) {
RED("Z");
}
else {
if(c[i][j] == 'P') {
YELLOW("P");
}
else if(c[i][j] == 'V') {
GREEN("V");
}
else if(c[i][j] == 'Z') {
RED("Z");
}
else {
cout << c[i][j];
}
}
}
cout << "\n";
}
hp--;
cout << "你死了!\n";
Sleep(2000);
goto a;
}
if(stop <= 0) {
M();
}
else {
stop--;
}
CD++;
if(c[x][y] == 'V') {
hp++;
}
if(c[x][y] == 'Z' || c[x][y] == 'L' || die == true) {
qp;
cout << "第" << Level << "关\n";
cout << "HP : " << hp << "\n";
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
if(i == x && j == y) {
if(c[i][j] == 'Z') {
RED("Z");
}
else {
cout << "@";
}
}
else {
if(c[i][j] == 'Z') {
RED("Z");
}
else if(c[i][j] == 'P') {
YELLOW("P");
}
else if(c[i][j] == 'V') {
GREEN("V");
}
else {
cout << c[i][j];
}
}
}
cout << "\n";
}
if(c[x][y] == 'Z' || die == true) {
hp--;
cout << "你死了!\n";
Sleep(2000);
goto a;
}
else {
system("color 7F");
cout << "你过关了!" << endl;
Sleep(2000);
Level++;
goto a;
}
}
c[x][y] = '@';
Sleep(10);
system("cls");
}
}
void learn() {
slowsay(20, "先进教程,学完了再实战,OK?");
Sleep(100);
len = CD = 0;
system("cls");
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
c[i][j] = '#';
}
}
for(int i = 2; i <= 19; i++) {
for(int j = 2; j <= 19; j++) {
c[i][j] = '.';
}
}
c[2][2] = '@';
ys(2);
slowsay(10, "@的位置是你,你可以按下大写的WASD移动\n");
slowsay(10, "你来试试看\n");
ys(0);
Sleep(1000);
int p = 10, hp = 3;
system("cls");
x = 2, y = 2;
while(p) {
cout << "HP : " << hp << "\n";
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
cout << c[i][j];
}
cout << "\n";
}
cout << "\n";
ys(0);
while(!kbhit()) {
}
char g = _getch();
if(g == 'W' && c[x - 1][y] == '.') {
c[x][y] = '.';
x--;
}
else if(g == 'A' && c[x][y - 1] == '.') {
c[x][y] = '.';
y--;
}
else if(g == 'S' && c[x + 1][y] == '.') {
c[x][y] = '.';
x++;
}
else if(g == 'D' && c[x][y + 1] == '.') {
c[x][y] = '.';
y++;
}
else {
p++;
}
p--;
qp;
c[x][y] = '@';
}
ys(2);
slowsay(10, "好了,现在你应该已经掌握怎么移动了。\n");
slowsay(10, "我会在中间生成一个回血道具V,吃了它\n");
ys(0);
Sleep(100);
c[x][y] = '.';
c[10][10] = 'V';
c[2][2] = '@';
qp;
x = 2, y = 2;
while(1) {
cout << "HP : " << hp << "\n";
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
if(c[i][j] == 'V') {
GREEN("V");
}
else {
cout << c[i][j];
}
}
cout << "\n";
}
cout << "\n";
if(hp == 4) {
ys(2);
slowsay(10, "你看,你吃掉了回血道具,现在你的生命值,也就是HP,增加了1\n");
Sleep(2000);
ys(0);
qp;
break;
}
ys(0);
while(!kbhit()) {
}
char g = _getch();
if(g == 'W' && c[x - 1][y] != '#') {
c[x][y] = '.';
x--;
}
else if(g == 'A' && c[x][y - 1] != '#') {
c[x][y] = '.';
y--;
}
else if(g == 'S' && c[x + 1][y] != '#') {
c[x][y] = '.';
x++;
}
else if(g == 'D' && c[x][y + 1] != '#') {
c[x][y] = '.';
y++;
}
if(c[x][y] == 'V') {
hp++;
}
qp;
c[x][y] = '@';
}
c[x][y] = '.';
ys(2);
slowsay(10, "接着,你要开始打怪了,毕竟怪物在迷宫里是必不可少的一部分。\n");
slowsay(10, "怪物是P,你要躲避它的子弹Z,你可以跑过去撸死它\n");
ys(0);
Sleep(3000);
qp;
x = 2, y = 2;
c[10][10] = 'P';
c[2][2] = '@';
while(c[10][10] == 'P') {
die = false;
cout << "HP : " << hp << "\n";
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
if(c[i][j] == 'Z') {
RED("Z");
}
else if(c[i][j] == 'V') {
GREEN("V");
}
else if(c[i][j] == 'P') {
YELLOW("P");
}
else {
cout << c[i][j];
}
}
cout << "\n";
}
if(c[x][y] == 'Z') {
cout << "你受到了伤害!\n";
c[x][y] = '@';
for(int i = 1; i <= len; i++) {
if(zd[i].x == x && zd[i].y == y) {
zd[i].d = -1;
}
}
Sleep(2000);
qp;
c[x][y] = '@';
continue;
}
while(!kbhit()) {
}
char g = _getch();
if(g == 'W' && c[x - 1][y] != '#') {
c[x][y] = '.';
x--;
}
else if(g == 'A' && c[x][y - 1] != '#') {
c[x][y] = '.';
y--;
}
else if(g == 'S' && c[x + 1][y] != '#') {
c[x][y] = '.';
x++;
}
else if(g == 'D' && c[x][y + 1] != '#') {
c[x][y] = '.';
y++;
}
if(c[x][y] == 'Z') {
qp;
cout << "HP : " << hp << "\n";
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
if(i == x && j == y || c[i][j] == 'Z') {
RED("Z");
}
else if(c[i][j] == 'P') {
YELLOW("P");
}
else if(c[i][j] == 'V') {
GREEN("V");
}
else {
cout << c[i][j];
}
}
cout << "\n";
}
cout << "你受到了伤害!\n";
Sleep(2000);
c[x][y] = '@';
for(int i = 1; i <= len; i++) {
if(zd[i].x == x && zd[i].y == y) {
zd[i].d = -1;
}
}
qp;
continue;
}
M();
CD++;
if(c[x][y] == 'V') {
hp++;
}
if(c[x][y] == 'Z' || die == true) {
qp;
cout << "HP : " << hp << "\n";
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
if(i == x && j == y || c[i][j] == 'Z') {
RED("Z");
}
else if(c[i][j] == 'P') {
YELLOW("P");
}
else if(c[i][j] == 'V') {
GREEN("V");
}
else {
cout << c[i][j];
}
}
cout << "\n";
}
c[x][y] = '@';
for(int i = 1; i <= len; i++) {
if(zd[i].x == x && zd[i].y == y) {
zd[i].d = -1;
}
}
cout << "你受到了伤害!\n";
Sleep(2000);
c[x][y] = '@';
qp;
continue;
}
c[x][y] = '@';
Sleep(10);
qp;
}
cout << "HP : " << hp << "\n";
for(int i = 1; i <= 20; i++) {
for(int j = 1; j <= 20; j++) {
cout << c[i][j];
}
cout << "\n";
}
ys(2);
slowsay(10, "你现在打死了怪物,后面的内容就靠你自己探索了!(主要是作者很懒)");
ys(0);
Sleep(3000);
qp;
}
void gz() {
slowsay(10, "在这个游戏中,'#'是墙,'.'是路,你的位置是'@',终点是L,WASD移动\n");
system("pause");
qp;
slowsay(10, "这个迷宫里有怪物'P'。\n");
system("pause");
qp;
slowsay(10, "TA虽然不会移动,但是怪物会向你发射子弹,敌人的子弹是'Z'。你被打到就会死翘翘,当然,你也可以跑过去徒手干掉它。\n");
system("pause");
qp;
slowsay(10, "在迷宫里,会有一些道具,V是回血的道具。注意,如果子弹打到道具,道具将被摧毁。哦,对了,忘说了,怪物也会被怪物打死。\n");
system("pause");
qp;
slowsay(10, "如果你发现地图有问题,按Q刷新地图\n");
system("pause");
qp;
slowsay(10, "接下来其他内容,就靠你自己探索了qwq\n");
}
int main()
{
qp;
WA:
qp;
cout<<"这是你第一次玩这款游戏吗?\n";
cout<<"1.Yes 2.No\n";
int Yes;
cin>>Yes;
if(Yes==1)
{
cout<<"请输入你的用户名:";
string c;
cin>>c;
cout<<"请输入你的密码(如果输入错误请关闭程序):";
char hh;
string ans;
while(hh!='\r')
{
hh=_getch();
ans+=hh;
cout<<"*";
}
cout<<endl;
read("开始核对密码,你的密码为:",30);
cout<<ans;
Sleep(2000);
cout<<"1.是的,这是我的密码 2.这不是我的密码!";
cout<<endl;
char l=_getch();
if(l=='1')
{
cout<<"保存成功!\n";
ofstream fout;
fout.open("账户信息.s");
fout<<ans<<endl<<c;
fout.close ();
Sleep(2000);
read("你的密码位于账户信息.s里面\n",30);
read("再见\n",30);
Sleep(2000);
goto WA;
}
else
{
cout<<"那你关闭程序在启动一次";
cout<<endl;
cout<<"我先停止运行了";
return 0;
}
}
else if(Yes==2)
{
ifstream fin;
ofstream fout;
cout<<"请输入你的账户名:";
string name;
cin>>name;
cout<<"请输入你的密码:";
string mima;
cin>>mima;
string ans,c;
fin.open("账户信息.s");
fin>>ans;
if(mima!=ans)
{
lllllllll:
cout<<"Jcer死";
return 0;
}
fin>>c;
if(c!=name)
{
goto lllllllll;
}
fin.close();
cout<<"验证成功\n";
Sleep(2000);
}
ys(1);
cout << " ■ ■ ■ ■■■■■ ■■■■■\n";
cout << " ■ ■ ■■ ■■ ■ ■\n";
cout << " ■ ■ ■ ■ ■ ■ ■ ■■■■■\n";
cout << " ■ ■■ ■ ■■■■ ■ ■\n";
cout << "■ ■ ■ ■ ■ ■■■■■ ■■■■■\n";
ys(0);
system("pause");
cout << "正在加载……";
qp;
for(int i = 1; i <= 100; i++) {
cout << "loading...\n";
cout << i << "%\n";
Sleep(7);
qp;
}
system("color 0F") ;
hp = 3, Level = 1, len = 0;
int xw;
a:
cout << "1. 开始游戏 2. 介绍规则 3.游戏教程\n";
cin >> xw;
if(xw == 1) {
game(1);
}
else if(xw == 2) {
gz();
}
else if(xw == 3) {
learn();
}
goto a;
return 0;
}