# brain-games **Repository Path**: narc/brain-games ## Basic Information - **Project Name**: brain-games - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-24 - **Last Updated**: 2026-02-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 益智小游戏合集 一个基于 uni-app + Vue 3 + TypeScript 开发的益智休闲类小游戏合集,支持 H5 网页端运行,可扩展到微信公众号和小程序。 ## 已上线游戏 | 游戏 | 描述 | 特色 | |-----|------|------| | 🎮 **2048** | 滑动合并数字,挑战2048! | 经典玩法、分数记录、最高分保存 | | 🎯 **舒尔特方格** | 按顺序点击数字,训练专注力 | 4种难度(3x3~6x6)、计时统计、错误记录 | | 🧠 **数字记忆** | 记住数字顺序,锻炼记忆力 | 关卡递进、难度递增、答案对比 | ## 技术栈 - **框架**: uni-app + Vue 3 - **语言**: TypeScript - **状态管理**: Pinia - **样式**: SCSS - **构建工具**: Vite ## 项目结构 ``` src/ ├── games/ # 游戏核心模块 │ ├── core/ # 基础框架 │ │ ├── BaseGame.ts # 游戏基类 │ │ └── types.ts # 类型定义 │ ├── game-2048/ # 2048游戏模块 │ ├── schulte-grid/ # 舒尔特方格模块 │ ├── number-memory/ # 数字记忆模块 │ ├── registry.ts # 游戏注册中心 │ └── index.ts │ ├── pages/ # 页面 │ ├── index/ # 首页(游戏列表) │ └── games/ # 游戏页面 │ ├── game-2048/ │ ├── schulte-grid/ │ └── number-memory/ │ ├── components/ # 公共组件 │ ├── GameCard.vue # 游戏卡片 │ ├── GameHeader.vue # 游戏头部(分数/时间) │ ├── GameResult.vue # 结果弹窗 │ └── Countdown.vue # 倒计时组件 │ ├── stores/ # Pinia状态管理 │ ├── game.ts # 游戏全局状态 │ └── user.ts # 用户数据(分数记录) │ ├── utils/ # 工具函数 │ ├── storage.ts # 本地存储封装 │ ├── audio.ts # 音效管理 │ └── vibration.ts # 震动反馈(多端适配) │ ├── styles/ # 全局样式 │ ├── static/ # 静态资源 │ ├── App.vue ├── main.ts ├── pages.json # 页面路由配置 └── uni.scss # 全局样式变量 ``` ## 快速开始 ### 安装依赖 ```bash npm install ``` ### 开发模式 ```bash # H5 网页端 npm run dev:h5 # 微信小程序 npm run dev:mp-weixin ``` ### 构建发布 ```bash # H5 网页端 npm run build:h5 # 微信小程序 npm run build:mp-weixin ``` ## 扩展新游戏 ### 1. 创建游戏模块 在 `src/games/` 目录下创建新游戏文件夹: ```typescript // src/games/my-game/MyGame.ts import { BaseGame } from '../core/BaseGame'; export class MyGame extends BaseGame { init() { /* 初始化逻辑 */ } start() { /* 开始游戏 */ } pause() { /* 暂停游戏 */ } resume() { /* 继续游戏 */ } reset() { /* 重置游戏 */ } } ``` ### 2. 注册游戏配置 在 `src/games/registry.ts` 添加配置: ```typescript export const gameConfigs: GameConfig[] = [ // ...现有游戏 { id: 'my-game', name: '我的游戏', icon: '/static/images/games/my-game.png', description: '游戏描述', color: '#FF6B6B', path: '/pages/games/my-game/index' } ]; ``` ### 3. 创建游戏页面 在 `src/pages/games/` 创建页面,并在 `pages.json` 添加路由: ```json { "path": "pages/games/my-game/index", "style": { "navigationBarTitleText": "我的游戏", "navigationBarBackgroundColor": "#FF6B6B", "navigationBarTextStyle": "white" } } ``` ## 架构设计 ### 游戏基类 所有游戏继承 `BaseGame` 基类,统一管理: - 游戏状态 - 分数系统 - 计时器 - 生命周期方法 ### 插件化架构 通过 `GameRegistry` 注册中心管理游戏模块,实现: - 游戏独立封装 - 动态注册/卸载 - 统一接口规范 ### 多端适配 使用条件编译处理平台差异: ```typescript // #ifdef H5 // H5专属代码 // #endif // #ifdef MP-WEIXIN // 微信小程序专属代码 // #endif ``` ## 功能特性 - ✅ 游戏模块独立可插拔 - ✅ 分数本地存储 - ✅ 最高分记录 - ✅ 计时功能 - ✅ 震动反馈 - ✅ 多端适配(H5/微信小程序) ## 后续规划 - [ ] 添加更多游戏 - [ ] 游戏音效 - [ ] 排行榜系统 - [ ] 成就系统 - [ ] 主题切换 - [ ] 微信小程序发布 ## License MIT