跳到正文

休闲·娱乐

迷宫小游戏

zykaris约 14 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 14 分钟
获赞
3

版本

  1. v1当前

WSAD键控制,回车键提交

C++
#include <bits/stdc++.h>

using namespace std;
string t[100][100] = {
    {"#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#"},
    {"#","○"," "," "," "," "," "," "," "," "," ","#"," "," "," ","#","#"," "," "," ","#"," ","#","#","#"," ","#","#","#","#"},
    {"#"," ","#","#","#","#","#","#"," ","#"," ","#"," ","#"," "," "," "," ","#"," ","#"," ","#","#","#"," ","#","#","#","#"},
    {"#"," ","#"," "," "," ","#","#"," ","#"," "," "," ","#"," ","#","#","#","#"," ","#"," ","#","#","#"," "," "," ","#","#"},
    {"#"," "," "," ","#"," ","#","#"," "," ","#","#","#"," "," "," "," ","#"," "," ","#"," "," ","#","#"," ","#","#","#","#"},
    {"#","#","#","#","#"," ","#"," "," "," "," "," ","#"," ","#","#","#","#","#"," ","#","#"," "," "," "," ","#","#","#","#"},
    {"#"," "," "," ","#"," ","#","#","#","#","#"," ","#"," "," "," ","#"," "," "," ","#"," ","#"," ","#"," "," "," "," ","#"},
    {"#"," ","#"," ","#"," "," "," "," ","#","#"," ","#"," ","#","#","#","#"," ","#","#"," ","#"," ","#"," ","#","#","#","#"},
    {"#"," ","#"," ","#"," ","#","#"," "," "," "," "," "," ","#","#"," "," "," "," "," "," ","#"," ","#"," ","#","#","#","#"},
    {"#"," ","#"," ","#"," ","#","#","#","#","#","#","#"," ","#","#"," ","#","#","#","#","#","#"," ","#"," "," "," ","#","#"},
    {"#"," ","#"," "," "," ","#","#"," "," "," ","#","#","#","#","#","#","#","#","#","#","#"," ","#","#","#"," "," "," ","#"},
    {"#"," ","#","#","#","#","#","#"," ","#"," ","#","#","#","#","#"," "," ","#"," "," "," "," "," "," "," "," ","#"," ","#"},
    {"#"," "," "," "," "," "," "," "," ","#"," ","#"," "," "," "," "," ","#","#","#","#","#"," ","#","#","#"," ","#"," ","出"},
    {"#"," ","#","#","#","#","#","#","#","#"," ","#","#","#","#","#"," ","#","#","#","#","#"," ","#","#","#"," ","#","#","#"},
    {"#"," "," "," "," "," ","#"," ","#","#"," ","#","#","#","#","#"," ","#","#","#"," "," "," "," "," "," "," ","#","#","#"},
    {"#","#","#","#","#"," ","#"," ","#","#"," ","#"," "," "," "," "," "," ","#","#","#","#","#","#","#","#"," ","#"," ","#"},
    {"#"," "," "," "," "," ","#"," ","#","#"," ","#","#"," ","#","#","#"," "," "," "," "," "," "," "," ","#"," "," "," ","#"},
    {"#"," ","#"," ","#","#","#"," "," "," "," "," "," "," ","#","#","#","#","#","#"," ","#","#","#","#","#","#","#"," ","#"},
    {"#"," ","#"," "," "," "," ","#","#","#"," ","#","#"," "," "," "," "," "," ","#"," "," "," "," "," "," "," "," "," ","#"},
    {"#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#"}
};

void show()
{
    for(int i = 0; i < 20; i++)
    {
        for(int j = 0; j < 30; j++)
        {
            cout << t[i][j];
        }
        cout << endl;
    }
    return ;
}

int main()
{
    char s;
    int a = 1, b = 1;
    while(true)
    {
        show();
        cout << "输入走向(WSAD)";
        cin >> s;
        if(s == 'W')
        {
			if(t[a - 1][b] == "出")
            {
                system("cls");
            	cout << "#########################################################" << endl;
            	cout << "#                                                       #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#             恭喜你走出了迷宫!!!!!!              #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#########################################################" << endl;
                break;
            }
            if(a > 0)
            {

                if(t[a - 1][b] != "#")
                {
                    swap(t[a - 1][b], t[a][b]);
                    a --;
                }
            }
        }
        else if(s == 'S')
        {
        	if(t[a + 1][b] == "出")
            {
                system("cls");
            	cout << "#########################################################" << endl;
            	cout << "#                                                       #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#             恭喜你走出了迷宫!!!!!!              #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#########################################################" << endl;
                break;
            }
            if(a < 20)
            {
                if(t[a + 1][b] != "#")
                {
                    swap(t[a + 1][b], t[a][b]);
                    a ++;
                }
            }
        }
        else if(s == 'A')
        {
        	if(t[a][b - 1] == "出")
            {
                system("cls");
            	cout << "#########################################################" << endl;
            	cout << "#                                                       #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#             恭喜你走出了迷宫!!!!!!              #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#########################################################" << endl;
                break;
            }
            if(b > 0)
            {
                if(t[a][b - 1] != "#")
                {
                    swap(t[a][b - 1], t[a][b]);
                    b --;
                }
            }
        }
        else if(s == 'D')
        {
        	if(t[a][b + 1] == "出")
            {
                system("cls");
            	cout << "#########################################################" << endl;
            	cout << "#                                                       #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#             恭喜你走出了迷宫!!!!!!              #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#                                                       #" << endl;
                cout << "#########################################################" << endl;
                break;
            }
            if(b < 30)
            {
                if(t[a][b + 1] != "#")
                {
                    swap(t[a][b + 1], t[a][b]);
                    b ++;
                }
            }
        }
        system("cls");
    }
    return 0;
}
原文