You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

48 lines
1.3 KiB

import ballMove from "./game-ballmove/game";
import flappyBird from "./game-flipbird/game";
import game2048 from "./game2048/game";
import rect from "./game-rect/game";
import floodFill from "./game-flood-fill/game";
import match3 from "./match3/game";
import slidingPuzzle from "./slidingPuzzle/index";
const attachMethods = (fn, isClass) => (...p) => {
const game = isClass ? new fn(...p) : fn(...p);
return Object.assign(game, {
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 functions = Object.entries({
ballMove,
flappyBird,
game2048,
rect,
floodFill,
match3,
}).map(([name, fn]) => ({ [name]: attachMethods(fn) }));
const classes = Object.entries({
slidingPuzzle,
}).map(([name, fn]) => ({ [name]: attachMethods(fn, true) }));
const games = functions
.concat(classes)
.reduce((acc, nxt) => Object.assign(acc, nxt), {});
export default games;