From aba33332256ab9c5f6ee849b0af197d260333b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=8A=E6=99=9A=E6=89=93=E8=80=81=E8=99=8E?= Date: Thu, 26 Mar 2026 20:59:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E6=8A=95=E7=A8=BF]=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC:=20=E8=BF=B7=E5=AE=AB=E5=B0=8F=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=20=E2=80=94=20by=20Daoyu268?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scripts/games/script_mn7hc213.py | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 script_library/scripts/games/script_mn7hc213.py diff --git a/script_library/scripts/games/script_mn7hc213.py b/script_library/scripts/games/script_mn7hc213.py new file mode 100644 index 0000000..6798c0d --- /dev/null +++ b/script_library/scripts/games/script_mn7hc213.py @@ -0,0 +1,108 @@ +import random + +# ------------- 核心配置 ------------- +MAZE_SIZE = 15 # 迷宫大小 (奇数) +PLAYER = "P" # 玩家 +EXIT = "E" # 出口 +WALL = "■" # 墙 +PATH = " " # 路径 + +# ------------- 核心函数 ------------- +def generate_maze(size): + """生成迷宫 (简化版,100% 有解)""" + maze = [[WALL for _ in range(size)] for _ in range(size)] + + # 从起点开始,随机打通路径 + x, y = 1, 1 + maze[y][x] = PATH + + # 简单的随机游走算法,确保迷宫连通 + for _ in range(size * size // 2): + # 随机选一个方向 + dx, dy = random.choice([(0,1), (0,-1), (1,0), (-1,0)]) + nx, ny = x + dx, y + dy + + # 检查是否在边界内且是墙 + if 1 <= nx < size-1 and 1 <= ny < size-1 and maze[ny][nx] == WALL: + maze[ny][nx] = PATH + x, y = nx, ny + + # 确保出口是通路 + maze[size-2][size-2] = PATH + return maze + +def print_screen(maze, px, py, ex, ey): + """直接打印迷宫,不使用任何系统清屏函数""" + print("\n" * 5) # 打印空行模拟清屏 + size = MAZE_SIZE + for y in range(size): + line = [] + for x in range(size): + if x == px and y == py: + line.append(PLAYER) + elif x == ex and y == ey: + line.append(EXIT) + else: + line.append(maze[y][x]) + print(''.join(line)) + +def show_menu(): + """显示操作菜单""" + print("\n===== [虚拟按钮] =====") + print("1. 向上 2. 向下") + print("3. 向左 4. 向右") + print("5. 重置游戏") + print("======================") + +def main(): + maze = generate_maze(MAZE_SIZE) + px, py = 1, 1 # 玩家起点 + ex, ey = MAZE_SIZE-2, MAZE_SIZE-2 # 出口 + + print("欢迎来到终端迷宫游戏!") + print("指令: 1/2/3/4 移动, 5 重置") + + while True: + print_screen(maze, px, py, ex, ey) + show_menu() + + # 获取用户输入 + try: + cmd = int(input("\n请输入操作: ")) + except: + print("输入错误,请输入数字 1-5!") + continue + + # 处理移动 + dx, dy = 0, 0 + if cmd == 1: dy = -1 + elif cmd == 2: dy = 1 + elif cmd == 3: dx = -1 + elif cmd == 4: dx = 1 + elif cmd == 5: + print("重置迷宫...") + maze = generate_maze(MAZE_SIZE) + px, py = 1, 1 + continue + else: + print("无效指令!") + continue + + # 计算新位置 + nx, ny = px + dx, py + dy + + # 检查碰撞 (不能撞墙,不能出界) + if (0 <= nx < MAZE_SIZE and + 0 <= ny < MAZE_SIZE and + maze[ny][nx] != WALL): + px, py = nx, ny + + # 检查胜利 + if px == ex and py == ey: + print("\n🎉 恭喜你!成功到达终点!") + input("按回车键继续...") + maze = generate_maze(MAZE_SIZE) + px, py = 1, 1 + +if __name__ == "__main__": + main() \ No newline at end of file From be79a56558ee420c63327edb15761dba266dd41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=8A=E6=99=9A=E6=89=93=E8=80=81=E8=99=8E?= Date: Thu, 26 Mar 2026 20:59:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E6=8A=95=E7=A8=BF]=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20index.json:=20=E6=B7=BB=E5=8A=A0=20=E8=BF=B7=E5=AE=AB?= =?UTF-8?q?=E5=B0=8F=E6=B8=B8=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script_library/index.json | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/script_library/index.json b/script_library/index.json index beeaef0..44e083a 100644 --- a/script_library/index.json +++ b/script_library/index.json @@ -1,7 +1,7 @@ { "format_version": 1, - "data_version": 26, - "updated": "2026-03-25T22:41:30.062Z", + "data_version": 27, + "updated": "2026-03-26T12:59:46.090Z", "announcement": null, "categories": [ { @@ -681,6 +681,29 @@ "updated": null, "status": "active", "lines": 57 + }, + { + "id": "script_mn7hc213", + "name": "迷宫小游戏", + "name_en": "迷宫小游戏", + "desc": "迷宫(简易)", + "desc_en": "迷宫(简易)", + "category": "games", + "file": "scripts/games/script_mn7hc213.py", + "thumbnail": null, + "version": 1, + "file_type": "py", + "author": "Daoyu268", + "author_en": "Daoyu268", + "tags": [ + "community" + ], + "requires": [], + "min_app_version": "1.5.0", + "added": "2026-03-26", + "updated": null, + "status": "active", + "lines": 108 } ] }