import ballMove from "./games/game-ballmove/game"; import flappyBird from "./games/game-flipbird/game"; import game2048 from "./games/game2048/game"; import rect from "./games/game-rect/game"; import floodFill from "./games/game-flood-fill/game"; import match3 from "./games/match3/game"; const attachMethods = (fn) => (...p) => Object.assign(fn(...p), { pause() { this.scene.scenes.forEach((scene) => { scene.scene.pause(); }); }, resume() { this.scene.scenes.forEach((scene) => { scene.scene.resume(); }); }, dispose() { for (const key in this.scene.keys) { if (this.scene.keys.hasOwnProperty(key)) { this.scene.stop(key); //停止渲染 this.scene.keys[key] = undefined; } } this.destroy(false); }, }); const games = Object.entries({ ballMove, flappyBird, game2048, rect, floodFill, match3, }) .map(([name, fn]) => ({ [name]: attachMethods(fn) })) .reduce((acc, nxt) => Object.assign(acc, nxt), {}); export default games;