Commit 18ebc83d authored by wildfirecode's avatar wildfirecode

1

parent d384b84c
......@@ -2,8 +2,8 @@ export default class PieceControl {
public scene;
private isDog: boolean;
private front;
private back;
private index: number;
public back;
public index: number;
static FLIP_DURTION = 1000;
public container;
......
......@@ -9,7 +9,7 @@ export default class SceneControl {
SHOW_TIME = 1000;
DELAY = 500;
BORNS = 2;
BORNS = 1;
R = 3;
TIMES = 3;
N = 4;
......@@ -22,40 +22,42 @@ export default class SceneControl {
}
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.back.setInteractive();
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();
// });
// });
p.back.on('clicked', () => {
// console.log(p.index);
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);
}
this.disable();
......@@ -84,14 +86,14 @@ export default class SceneControl {
}
disable() {
// for (const e of this._list) {
// e.mouseEnabled = false;
// }
this.scene.input.off('gameobjectup', this.ongameobjectup, this);
}
enable() {
// for (const e of this._list) {
// e.mouseEnabled = true;
// }
this.scene.input.on('gameobjectup', this.ongameobjectup, this);
}
ongameobjectup(pointer, gameObject){
gameObject.emit('clicked', gameObject);
}
}
\ No newline at end of file
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