初始提交:三玩法 Web 原型与设计文档
- 玩法一 数字一笔:规则库、求解器、26 关、竖屏触摸 Web 原型、测试 - 玩法二 连连气球:连消畅玩版核心、Web 原型、Cocos 球槽组件与导出脚本 - 玩法三 六边一笔:规则库、求解器、10 关 + 转墙实验包、Web 原型、测试 - 产品文档、UI 设计规范、各玩法 GDD / HANDOFF - 文档移除全部外部参考作引用;删除玩法二 v0 旧稿
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import type { StoragePort } from './storage';
|
||||
import type { FlowStats } from './flow';
|
||||
export const FLOW_SAVE_KEY = 'mode:02-connect-1234:balloons-v2';
|
||||
export interface FlowRecord { version: 2; bestScore: number; bestNumber: number; bestCombo: number; bestFlown: number; sound: boolean }
|
||||
export function freshRecord(): FlowRecord { return { version: 2, bestScore: 0, bestNumber: 0, bestCombo: 0, bestFlown: 0, sound: true }; }
|
||||
export function loadRecord(storage: StoragePort): FlowRecord {
|
||||
const result = freshRecord();
|
||||
try {
|
||||
const saved = JSON.parse(storage.read(FLOW_SAVE_KEY) || 'null');
|
||||
if (saved?.version !== 2) return result;
|
||||
for (const key of ['bestScore', 'bestNumber', 'bestCombo', 'bestFlown'] as const)
|
||||
if (Number.isSafeInteger(saved[key]) && saved[key] >= 0) result[key] = saved[key];
|
||||
if (typeof saved.sound === 'boolean') result.sound = saved.sound;
|
||||
} catch { /* 损坏或不可用存储不影响游玩 */ }
|
||||
return result;
|
||||
}
|
||||
export function recordRound(record: FlowRecord, stats: FlowStats): void {
|
||||
record.bestScore = Math.max(record.bestScore, stats.score);
|
||||
record.bestNumber = Math.max(record.bestNumber, stats.maxNumber);
|
||||
record.bestCombo = Math.max(record.bestCombo, stats.bestCombo);
|
||||
record.bestFlown = Math.max(record.bestFlown, stats.flown);
|
||||
}
|
||||
export function saveRecord(storage: StoragePort, record: FlowRecord): boolean {
|
||||
try { storage.write(FLOW_SAVE_KEY, JSON.stringify(record)); return true; } catch { return false; }
|
||||
}
|
||||
Reference in New Issue
Block a user