迷宫游戏2.1.1

· · 休闲·娱乐

爆肝1h肝出来的幸运方块版迷宫游戏。

#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;

using namespace std;

const int MAXN = 1e2, MAXK = 1e6 + 1; 
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, see = 0;
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[MAXK];
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') {
                        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') {
                        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') {
                        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') {
                        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() % 100 + 1;
                if(x <= 20) {
                    c[i][j] = '#';
                }
                else if(x <= 70) {
                    c[i][j] = '.';
                }
                else if(x <= 71) {
                    c[i][j] = 'H';
                }
                else if(x <= 80) {
                    c[i][j] = 'P';
                }
                else if(x <= 83) {
                    c[i][j] = 'V';
                }
                else {
                    c[i][j] = '?';
                }
            }
        }
    }
    c[2][2] = '@', c[19][19] = 'L'; 
}
void out_mp() {
    if(see == 1 || see == 2) {
        for(int i = 1; i <= 20; i++) {
            for(int j = 1; j <= 20; j++) {
                if(i < max(x - 5, 1) || i > min(x + 5, 20) || j < max(y - 5, 1) || j > min(y + 5, 20)) {
                    cout << " ";
                }
                else {
                    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] == 'H') {
                        ys(1);
                        cout << "H";
                        ys(0);
                    }
                    else if(i == x && j == y) {
                        if(see == 1) {
                            ys(5);
                            cout << "@";
                            ys(0);
                        }
                        if(see == 2) {
                            ys(3);
                            cout << "@";
                            ys(0);
                        }
                    }
                    else if(c[i][j] == '?') {
                        int x = rand() % 4 + 1;
                        if(x == 1) {
                            RED("?");
                        }
                        if(x == 2) {
                            BLUE("?");
                        }
                        if(x == 3) {
                            GREEN("?");
                        }
                        if(x == 4) {
                            YELLOW("?");
                        }
                    }
                    else {
                        cout << c[i][j];
                    }
                }
            }
            cout << "\n";
        }
    }
    else {
        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(i == x && j == y && see == -1) {
                    ys(2);
                    cout << "@";
                    ys(0);
                }
                else if(c[i][j] == 'H') {
                    ys(1);
                    cout << "H";
                    ys(0);
                }
                else if(c[i][j] == '?') {
                    int x = rand() % 4 + 1;
                    if(x == 1) {
                        RED("?");
                    }
                    if(x == 2) {
                        BLUE("?");
                    }
                    if(x == 3) {
                        GREEN("?");
                    }
                    if(x == 4) {
                        YELLOW("?");
                    }
                }
                else {
                    cout << c[i][j];
                }
            }
            cout << "\n";
        }
    }
}
void hp_change(bool yhy) {
    if(yhy) {
        system("color 02");
        system("color 07");
        system("color 02");
        system("color 07");
        system("color 02");
        system("color 07");
        system("color 02");
        system("color 07");
        system("color 02");
        system("color 07");
    }
    else {
        system("color 40");
        system("color 07");
        system("color 40");
        system("color 07");
        system("color 40");
        system("color 07");
        system("color 40");
        system("color 07");
        system("color 40");
        system("color 07");
    }
}
void game(int p) {
    cout << "这个游戏是由PJL制作,并在迷宫游戏2.0上修改了一些的作品!\n";
    cout << "这个作品叫\"迷宫游戏2.1.1\"!\n";
    system("pause");
    system("cls");
    cout << "好了好了,废话不多说,开始游戏!";
    Sleep(500);
    system("cls");
    a :
    hp = 3;
    system("color 0F");
    system("cls"); 
    len = CD = stop = 0;
    Level++;
    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();
    see = 0;
    x = 2, y = 2;
    while(1) {
        die = false;
        cout << "第" << Level << "关 ";
        cout << "HP : " << hp << "   ";
        cout << "状态:" << (see == -1 ? "移动反转" : (see == 1 ? "部分视野" : (see == 2 ? "部分视野+移动反转" : "正常"))) << "\n"; 
        out_mp();
        while(!kbhit()) {
        }
        int nx = x, ny = y, lx = x, ly = y;
        char g = _getch();
        if(g == 'Q') {
            Level--;
            system("cls");
            goto a;
        }
        else if(g == 'W') {
            nx = x + (see == -1 || see == 2 ? -1 * dx[0] : dx[0]), ny = y + (see == -1 || see == 2 ? -1 * dy[0] : dy[0]);
        }
        else if(g == 'A') {
            nx = x + (see == -1 || see == 2 ? -1 * dx[2] : dx[2]), ny = y + (see == -1 || see == 2 ? -1 * dy[2] : dy[2]);
        }
        else if(g == 'S') {
            nx = x + (see == -1 || see == 2 ? -1 * dx[1] : dx[1]), ny = y + (see == -1 || see == 2 ? -1 * dy[1] : dy[1]);
        }
        else if(g == 'D') {
            nx = x + (see == -1 || see == 2 ? -1 * dx[3] : dx[3]), ny = y + (see == -1 || see == 2 ? -1 * dy[3] : dy[3]);
        }
        if(nx >= 1 && nx <= 20 && ny >= 1 && ny <= 20 && c[nx][ny] != '#') {
            x = nx, y = ny;
        }
        c[lx][ly] = '.';
        if(c[x][y] == 'Z') {
            hp--;
            hp_change(false);
        } 
        if(stop <= 0) {
            M();
        }
        else {
            stop--;
        }
        CD++;
        if(c[x][y] == 'V') {
            hp++;
        }
        if(c[x][y] == 'H') {
            cout << "随机化传送!(当心传送到子弹上!)\n";
            Sleep(1000);
            c[x][y] = '.';
            x = rand() % 18 + 2, y = rand() % 18 + 2;
        }
        if(c[x][y] == '?') {
            cout << "触发(并不怎么)幸运方块!\n";
            int x = rand() % 100 + 1;
            if(x <= 10) {
                hp++;
                cout << "血量增加了!\n";
                hp_change(true);
            }
            else if(x <= 50) {
                hp--;
                cout << "扣血了,好耶!\n";
                hp_change(false);
            } 
            else if(x <= 70) {
                cout << "你变为部分视野!\n";
                see = (see == -1 ? 2 : 1);
            }
            else if(x <= 85) {
                cout << "你变为移动反转!(手残党小心了!)\n";
                see = (see == 1 ? 2 : -1);
            }
            else if(x <= 90) {
                cout << "你被随机化传送了!(纯纯看你运气)\n";
                x = rand() % 18 + 2, y = rand() % 18 + 2;
            }
            else {
                cout << "状态被重置了!\n";
                see = 0;
            }
            Sleep(1500);
        }
        if(c[x][y] == 'Z' || die) {
            hp--;
            hp_change(false);
        }
        if(c[x][y] == 'L') {
            cout << "你过关!(美妙のBGM)\n";
            Sleep(3000);
            system("cls");
            goto a;
        }
        if(hp <= 0) {
            cout << "你死了,菜就多练。\n";
            Sleep(3000);
            system("cls");
            Level = 0;
            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--;
        system("cls");
        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] = '@';
    system("cls");
    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);
            system("cls");
            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++;
        }
        system("cls");
        c[x][y] = '@';
    }
    c[x][y] = '.';
    ys(2);
    slowsay(10, "接着,你要开始打怪了,毕竟怪物在迷宫里是必不可少的一部分。\n");
    slowsay(10, "怪物是P,你要躲避它的子弹Z,你可以跑过去撸死它\n");
    ys(0);
    Sleep(3000);
    system("cls");
    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);
            system("cls"); 
            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') {
            system("cls");
            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;
                }
            }
            system("cls");
            continue; 
        } 
        M();
        CD++;
        if(c[x][y] == 'V') {
            hp++;
        }
        if(c[x][y] == 'Z' || die == true) {
            system("cls");
            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] = '@';
            system("cls");
            continue; 
        }
        c[x][y] = '@';
        Sleep(10);
        system("cls");
    }
    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);
    system("cls"); 
} 
void gz() {
    slowsay(10, "在这个游戏中,'#'是墙,'.'是路,你的位置是'@',终点是L,WASD移动\n");
    system("pause");
    system("cls"); 
    slowsay(10, "这个迷宫里有怪物'P'。\n");
    system("pause");
    system("cls"); 
    slowsay(10, "TA虽然不会移动,但是怪物会向你发射子弹,敌人的子弹是'Z'。你被打到就会死翘翘,当然,你也可以跑过去徒手干掉它。\n");
    system("pause");
    system("cls"); 
    slowsay(10, "在迷宫里,会有一些道具,V是回血的道具。注意,如果子弹打到道具,道具将被摧毁。哦,对了,忘说了,怪物也会被怪物打死。\n");
    system("pause");
    system("cls"); 
    slowsay(10, "咳咳,说一件小事,游戏更新出了新玩法!会出现幸运方块'?',这b玩意可能会导致一些负面效果,特别坑人,能别用就别用,如果用了的话……嘿嘿嘿\n");
    system("pause");
    system("cls"); 
    slowsay(10, "咳咳,再说一件小事,游戏更新出了新玩法!会出现脆皮传送门'H',这b玩意可能把你传送到别的地方,特别坑人,能别用就别用,如果用了的话……嘿嘿嘿\n");
    system("pause");
    system("cls"); 
    slowsay(10, "如果你发现地图有问题,按Q刷新地图\n");
    system("pause");
    system("cls"); 
    slowsay(10, "接下来其他内容,就靠你自己探索了qwq\n"); 
}

int main() {
    srand(time(0));
    cout << "版权 __PJL__\n日期 2024/6/5\n语言 C++\n\n\n";
    slowsay(10, "欢迎游玩由__PJL__制作的迷宫游戏\n");
    ys(1);
    cout << "    ■       ■            ■        ■■■■■      ■■■■■\n";
    cout << "   ■ ■    ■■          ■■             ■        ■\n";
    cout << "  ■   ■  ■  ■        ■  ■          ■          ■■■■■\n";
    cout << " ■     ■■    ■      ■■■■       ■            ■\n";
    cout << "■       ■      ■    ■      ■    ■■■■■      ■■■■■\n";
    ys(0);
    system("pause");
    cout << "正在加载……";
    system("cls");
    for(int i = 1; i <= 100; i++) {
        cout << "loading...\n";
        cout << i << "%\n";
        Sleep(7);
        system("cls");
    }
    a :
    system("color 0F") ;
    hp = 3, Level = 1, len = 0;
    int x;
    cout << "1. 开始游戏 2. 介绍规则 3.游戏教程\n";
    cin >> x;
    if(x == 1) {
        game(1);
    }
    else if(x == 2) {
        gz();
    }
    else if(x == 3) {
        learn();
    }
    system("pause");
    system("cls");
    goto a;
    return 0;
}