Commit d384b84c authored by wildfirecode's avatar wildfirecode

1

parent 975c66c3
export default class PieceControl { export default class PieceControl {
private scene; public scene;
private isDog: boolean; private isDog: boolean;
private front; private front;
private back; private back;
...@@ -38,7 +38,9 @@ export default class PieceControl { ...@@ -38,7 +38,9 @@ export default class PieceControl {
scaleX: 1, scaleX: 1,
ease:'Quad.easeInOut', ease:'Quad.easeInOut',
duration: PieceControl.FLIP_DURTION / 2, duration: PieceControl.FLIP_DURTION / 2,
onComplete: () => { callback && callback() } onComplete: () => {
callback && callback()
}
}] }]
}); });
} }
......
// import Piece from './Piece';
// import * as utils from './utils'
// import Swap from './Swap';
// export default class Scene extends createjs.Container {
// private _targets: number[];
// private _list: Piece[];
// SHOW_TIME = 1000;
// DELAY = 500;
// BORNS = 1;
// R = 3;
// TIMES = 3;
// N = 4;
// SIZE = 235;
// constructor() {
// super();
// this.initUI();
// this.update();
// }
// initUI() {
// const n = this.R * this.R;
// const targetList = utils.fillN(n);
// const randomTargetList = utils.shuffle(targetList);
// this._targets = randomTargetList.slice(0, this.BORNS);
// this._list = [];
// for (let index = 1; index <= n; index++) {
// const inTargets = this._targets.indexOf(index) != -1;
// const p = new Piece(!inTargets, index);
// p['index'] = index;
// this.addChild(p);
// this._list.push(p);
// p.x = ((index - 1) % this.R) * this.SIZE;
// p.y = Math.floor((index - 1) / this.R) * this.SIZE;
// p.flipImmediately();
// p.addEventListener('click', (e: createjs.MouseEvent) => {
// const p = (e.currentTarget as Piece);
// this.disable();
// let enable = false;
// const index = this._targets.indexOf(p.index);
// if (index != -1) {
// this._targets.splice(index, 1);
// if (this._targets.length == 0) {
// console.log('good.')
// } else {
// enable = true;
// }
// }
// else {
// console.log('sorry.')
// }
// p.flip(() => {
// if (enable) this.enable();
// });
// });
// }
// this.disable();
// }
// update() {
// const onResetComplete = () => {
// setTimeout(() => {
// Swap.startSwap(this._list, this.N, this.TIMES, this._targets[0], () => {
// this.onSwapComplete()
// })
// }, this.DELAY);
// }
// setTimeout(() => {
// for (let i = 0; i < this._list.length; i++) {
// const e = this._list[i];
// e.reset(i == 0 ? onResetComplete : null);
// }
// }, this.SHOW_TIME);
// }
// onSwapComplete() {
// console.log('onSwapComplete');
// this.enable();
// }
// disable() {
// for (const e of this._list) {
// e.mouseEnabled = false;
// }
// }
// enable() {
// for (const e of this._list) {
// e.mouseEnabled = true;
// }
// }
// }
\ No newline at end of file
import PieceControl from './PieceControl';
import * as utils from './utils'
import Swap from './Swap';
export default class SceneControl {
private scene;
private _targets: number[];
private _list: PieceControl[];
SHOW_TIME = 1000;
DELAY = 500;
BORNS = 2;
R = 3;
TIMES = 3;
N = 4;
SIZE = 235;
constructor(scene) {
this.scene = scene;
this.initUI();
this.update();
}
initUI() {
const n = this.R * this.R;
const targetList = utils.fillN(n);
const randomTargetList = utils.shuffle(targetList);
this._targets = randomTargetList.slice(0, this.BORNS);
this._list = [];
for (let index = 1; index <= n; index++) {
const inTargets = this._targets.indexOf(index) != -1;
const p = new PieceControl(this.scene, !inTargets, index);
p['index'] = index;
this._list.push(p);
p.container.x = ((index - 1) % this.R) * this.SIZE + 106 + 50;
p.container.y = Math.floor((index - 1) / this.R) * this.SIZE + 106 + 50;
p.flipImmediately();
// p.addEventListener('click', (e: createjs.MouseEvent) => {
// const p = (e.currentTarget as Piece);
// this.disable();
// let enable = false;
// const index = this._targets.indexOf(p.index);
// if (index != -1) {
// this._targets.splice(index, 1);
// if (this._targets.length == 0) {
// console.log('good.')
// } else {
// enable = true;
// }
// }
// else {
// console.log('sorry.')
// }
// p.flip(() => {
// if (enable) this.enable();
// });
// });
}
this.disable();
}
update() {
const onResetComplete = () => {
setTimeout(() => {
Swap.startSwap(this._list, this.N, this.TIMES, this._targets[0], () => {
this.onSwapComplete()
})
}, this.DELAY);
}
setTimeout(() => {
for (let i = 0; i < this._list.length; i++) {
const e = this._list[i];
e.reset(i == 0 ? onResetComplete : null);
}
}, this.SHOW_TIME);
}
onSwapComplete() {
console.log('onSwapComplete');
this.enable();
}
disable() {
// for (const e of this._list) {
// e.mouseEnabled = false;
// }
}
enable() {
// for (const e of this._list) {
// e.mouseEnabled = true;
// }
}
}
\ No newline at end of file
// import * as utils from './utils' import * as utils from './utils'
// import Piece from './Piece'; import PieceControl from './PieceControl';
// export default class Swap { export default class Swap {
// static DURATION = 0.25; static DURATION = 0.45;
// static DELAY = .9; static DELAY = .9;
// static startSwap(all: Piece[], n: number, times: number, target: number, onSwapComplete: Function) { static startSwap(all: PieceControl[], n: number, times: number, target: number, onSwapComplete: Function) {
// for (let index = 0; index < times; index++) { for (let index = 0; index < times; index++) {
// const list = Swap.getList(all, n, target); const list = Swap.getList(all, n, target);
// setTimeout(() => { setTimeout(() => {
// Swap.swap(list, index + 1 == times ? onSwapComplete : null); Swap.swap(list, index + 1 == times ? onSwapComplete : null);
// }, Swap.DURATION * 1000 * index + Swap.DELAY * 1000 * index); }, Swap.DURATION * 1000 * index + Swap.DELAY * 1000 * index);
// } }
// } }
// private static getList(all: Piece[], n: number, target: number) { private static getList(all: PieceControl[], n: number, target: number) {
// const randomizedDeck = utils.shuffle(all); const randomizedDeck = utils.shuffle(all);
// let targetPiece; let targetPiece;
// const randomizedDeck2 = randomizedDeck.filter(e => { const randomizedDeck2 = randomizedDeck.filter(e => {
// if (e.index == target) if (e.index == target)
// targetPiece = e; targetPiece = e;
// return e.index != target; return e.index != target;
// }); });
// const list = randomizedDeck2.slice(0, n - 1); const list = randomizedDeck2.slice(0, n - 1);
// const m = n / 2; const m = n / 2;
// const list1 = list.slice(0, m); const list1 = list.slice(0, m);
// const list2 = list.slice(m); const list2 = list.slice(m);
// list2.push(targetPiece); list2.push(targetPiece);
// return list1.map( return list1.map(
// (val, index) => { return { a: val, b: list2[index] } } (val, index) => { return { a: val, b: list2[index] } }
// ) )
// } }
// private static swap(list: { a: Piece, b: Piece }[], onComplete: Function = null) { private static swap(list: { a: PieceControl, b: PieceControl }[], onComplete: Function = null) {
// let tag = true; let tag = true;
// for (const e of list) { for (const e of list) {
// if (tag) { if (tag) {
// tag = false; tag = false;
// Swap.swapOne(e.a, e.b, onComplete); Swap.swapOne(e.a, e.b, onComplete);
// } else { } else {
// Swap.swapOne(e.a, e.b); Swap.swapOne(e.a, e.b);
// } }
// } }
// } }
// private static swapOne(a: Piece, b: Piece, onComplete: Function = null) { private static swapOne(a: PieceControl, b: PieceControl, onComplete: Function = null) {
// const ax = a.x; const ax = a.container.x;
// const ay = a.y; const ay = a.container.y;
// const bx = b.x; const bx = b.container.x;
// const by = b.y; const by = b.container.y;
// const ease = createjs.Ease.quadInOut; const scene = a.scene;
// // if (onComplete) if (onComplete) {
// // annie.Tween.to(b, Swap.DURATION, { x: ax, y: ay, onComplete: onComplete, ease: ease }); const tween = scene.tweens.add({
// // else targets: b.container,
// // annie.Tween.to(b, Swap.DURATION, { x: ax, y: ay, ease: ease }); x: ax, y: ay,
// // annie.Tween.to(a, Swap.DURATION, { x: bx, y: by, ease: ease }); ease: 'Quad.easeInOut',
// } duration: Swap.DURATION*1000,
// } onComplete: onComplete
\ No newline at end of file });
}
else {
const tween = scene.tweens.add({
targets: b.container,
x: ax, y: ay,
ease: 'Quad.easeInOut',
duration: Swap.DURATION*1000,
});
}
const tween = scene.tweens.add({
targets: a.container,
x: bx, y: by,
ease: 'Quad.easeInOut',
duration:Swap.DURATION*1000,
});
}
}
\ No newline at end of file
import PieceControl from "./PieceControl"; import PieceControl from "./PieceControl";
import SceneControl from "./SceneControl";
const gameconfig = { const gameconfig = {
type: Phaser.AUTO, type: Phaser.AUTO,
width: 800, width: 800,
height: 600, height: 800,
scene: { scene: {
preload: preload, preload: preload,
create: create, create: create,
...@@ -20,14 +21,15 @@ function preload() { ...@@ -20,14 +21,15 @@ function preload() {
} }
function create() { function create() {
const a = new PieceControl(this, true, 0); new SceneControl(this)
a.container.x = 107; // const a = new PieceControl(this, true, 0);
a.container.y = 107; // a.container.x = 107;
// a.container.y = 107;
// a.container.visible =false // a.container.visible =false
a.resetImmediately(); // a.resetImmediately();
setTimeout(() => { // setTimeout(() => {
a.flip(); // a.flip();
}, 1000); // }, 1000);
// a.container.scaleX = 0.5 // a.container.scaleX = 0.5
// a.flipImmediately(); // a.flipImmediately();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment