#include \n#include \n#include \n#include \n\nusing namespace std;\n\nconst char WALL = '\u25FC';\nconst char START = 'S';\nconst char END = 'E';\nconst char PATH = ' ';\nconst char VISITED = '.';\nconst int MAX_SCORE = 100;\n\nclass MazeGame {\npublic:\n MazeGame(int size, int difficulty) : size(size), difficulty(difficulty) {\n // 初始化迷宫\n maze = vector<vector>(size, vector(size, WALL));\n for (int i = 1; i < size - 1; i++) {\n for (int j = 1; j < size - 1; j++) {\n maze[i][j] = PATH;\n }\n }\n\n // 随机生成起点和终点\n srand(time(nullptr));\n startRow = rand() % (size - 2) + 1;\n startCol = rand() % (size - 2) + 1;\n endRow = rand() % (size - 2) + 1;\n endCol = rand() % (size - 2) + 1;\n maze[startRow][startCol] = START;\n maze[endRow][endCol] = END;\n\n // 随机生成难度相关的岔路口数量\n int numBranches = size * difficulty / 10;\n for (int i = 0; i < numBranches; i++) {\n int row = rand() % (size - 2) + 1;\n int col = rand() % (size - 2) + 1;\n maze[row][col] = WALL;\n }\n }\n\n void play() {\n int score = 0;\n int numSteps = 0;\n vector<pair<int, int>> path;\n\n int curRow = startRow;\n int curCol = startCol;\n\n while (curRow != endRow || curCol != endCol) {\n maze[curRow][curCol] = VISITED;\n path.push_back(make_pair(curRow, curCol));\n\n cout << "当前位置:(" << curRow << ", " << curCol << ")" << endl;\n printMaze();\n\n // 接受用户输入\n char move;\n cout << "请输入移动方向(w上,s下,a左,d右):";\n cin >> move;\n\n int nextRow = curRow;\n int nextCol = curCol;\n\n // 根据用户输入计算下一步的位置\n switch (move) {\n case 'w':\n nextRow--;\n break;\n case 's':\n nextRow++;\n break;\n case 'a':\n nextCol--;\n break;\n case 'd':\n nextCol++;\n break;\n default:\n cout << "无效的移动方向!" << endl;\n continue;\n }\n\n // 判断下一步是否合法\n if (maze[nextRow][nextCol] == WALL) {\n cout << "撞墙了!" << endl;\n continue;\n }\n\n // 更新位置\n curRow = nextRow;\n curCol = nextCol;\n numSteps++;\n }\n\n // 到达终点\n score = MAX_SCORE - numSteps * difficulty;\n cout << "恭喜你成功走出迷宫!得分:" << score << endl;\n\n // 回放过程\n for (const auto& p : path) {\n maze[p.first][p.second] = PATH;\n printMaze();\n }\n }\n\nprivate:\n void printMaze() {\n for (int i = 0; i < size; i++) {\n for (int j = 0; j < size; j++) {\n cout << maze[i][j] << " ";\n }\n cout << endl;\n }\n cout << endl;\n }\n\n int size;\n int difficulty;\n vector<vector> maze;\n int startRow, startCol;\n int endRow, endCol;\n};\n\nint main() {\n int size, difficulty;\n cout << "请输入迷宫的大小(3~10之间的整数):";\n cin >> size;\n cout << "请输入迷宫的难度(1~10之间的整数):";\n cin >> difficulty;\n\n MazeGame game(size, difficulty);\n game.play();\n\n return 0;\n}