2 changed files with 49 additions and 24 deletions
@ -0,0 +1,38 @@ |
|||||
|
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"; |
||||
|
const canvas = document.createElement("canvas"); |
||||
|
const attachMethods = (fn) => (config) => |
||||
|
Object.assign(fn(Object.assign(config, { canvas })), { |
||||
|
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; |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
}); |
||||
|
const games = Object.entries({ |
||||
|
ballMove, |
||||
|
flappyBird, |
||||
|
game2048, |
||||
|
rect, |
||||
|
floodFill, |
||||
|
}) |
||||
|
.map(([name, fn]) => ({ [name]: attachMethods(fn) })) |
||||
|
.reduce((acc, nxt) => Object.assign(acc, nxt), {}); |
||||
|
|
||||
|
export default games; |
||||
Loading…
Reference in new issue