const config = { count: 5, // 默认倒计时时长 duration: 60, // 总时长 s total: 100, // 总分 times: 20, // 动作次数 level: 1, // 游戏难度级别 mode: 1, // 模式 0-> 正常模式 1-> 演示模式 currentScore: 0, // 当前得分 currentTimes: 0, // 当前次数 config: { scores: [{ direction: 0, score: 5 }], directions: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], }, // 得分配置 }; let library = null; let state = 0; // 游戏状态 0->未开始 1->进行中 2->结束 3->暂停 let isDemo = false; // 是不是演示模式 let leftDuration = null; // 暂停时的时间 function initStage(lib) { library = lib; window.main = Main.of(gameOver); // 初始化鸟等 window.timeInstance = Time.of(gameOver); // 初始化游戏时间 window.soundInstance = Sound.of(); // 初始化音频 Level.of(config.level); // 游戏难度级别 Back.of(); // 返回按钮 isHash(); window.suspend = Suspend.of(); window.addEventListener( 'click', function () { if (!window.soundInstance) return; window.soundInstance.playBgm(); }, false, ); } // 游戏结束 显示结束得分面板 function gameOver() { state = 2; const times = main.times; setTimeout(() => { End.of(config.currentScore || 0); if (config.mode === 0) { finishMessage(config.currentScore, times); } }, 2000); }