Commit 589c0357 authored by rockyl's avatar rockyl

Merge remote-tracking branch 'origin/dev' into dev

parents ca76151e b5cf2632
......@@ -63,7 +63,7 @@ function launchWithCustomModule(customModule) {
// blockUrl: "888"
// });
// }, 5*1000);
// }, 30*1000);
});
engine.globalEvent.addEventListener('pictures-time-update', (e) => {
// console.log(e.type, e.data);
......
......@@ -100,7 +100,7 @@
var _this = this;
if (!this.guideHole) {
this.guideHole = new engine.Image();
this.guideHole.source = 'asset://' + props.blockUrl;
this.guideHole.source = "asset://" + props.blockUrl;
this.guideHole.mouseChildren = this.guideHole.mouseEnabled = false;
}
if (this.pictures) {
......@@ -110,8 +110,8 @@
pic.parent.removeChild(pic);
}
}
console.log('on start');
engine.globalEvent.dispatchEvent('pictures-time-update', {
console.log("on start");
engine.globalEvent.dispatchEvent("pictures-time-update", {
second: this.getSecond(),
});
var result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);
......@@ -140,15 +140,17 @@
GAME_TIME = this.afterPointTwo(GAME_TIME);
GAME_TIME = GAME_TIME.toFixed(2);
if (GAME_TIME < 10) {
GAME_TIME = '0' + GAME_TIME;
GAME_TIME = "0" + GAME_TIME;
}
engine.globalEvent.dispatchEvent('pictures-time-update', {
console.log(GAME_TIME);
engine.globalEvent.dispatchEvent("pictures-time-update", {
second: this.getSecond(),
});
if (this.getSecond() == 0) {
GAME_TIME = props.GAME_TIME;
this.stop();
engine.globalEvent.dispatchEvent('pictures-game-fail', {
reason: 1
engine.globalEvent.dispatchEvent("pictures-game-fail", {
reason: 1,
});
}
};
......@@ -164,8 +166,8 @@
return GAME_TIME;
};
GameView.prototype.stop = function () {
GAME_TIME = props.GAME_TIME;
clearInterval(this._timer);
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
var len = this.pictures.length;
for (var i = 0; i < len; i++) {
this.pictures[i].removeAllEventListener();
......@@ -181,7 +183,7 @@
GAP = props.GAP;
w = W / MAX_COL;
h = H / MAX_ROW;
console.log('onSteup', props);
console.log("onSteup", props);
var parent = new engine.Sprite();
this.picturesWrapper = parent;
this.addChild(parent);
......@@ -195,74 +197,77 @@
this.localPicY = e.localY / MAX_ROW;
this.distanceX = this.dragPic.x;
this.distanceY = this.dragPic.y;
this.indexJ = Math.floor((this.distanceX) / (w + GAP));
this.indexI = Math.floor((this.distanceY) / (h + GAP));
this.index = (this.indexI) * MAX_COL + this.indexJ;
this.indexJ = Math.floor(this.distanceX / (w + GAP));
this.indexI = Math.floor(this.distanceY / (h + GAP));
this.index = this.indexI * MAX_COL + this.indexJ;
this.centerX = Math.floor((e.clientX - stageLeft) / w) * w + w / 2;
this.centerY = Math.floor((e.clientY - stageTop) / h) * h + h / 2;
this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
this.stage.addEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
};
GameView.prototype.stageOnUp = function (e) {
var stageLeft = (750 - props.W) / 2;
var stageTop = (this.stage.height - props.H) / 2;
this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
if (this.centerY < stageTop || this.centerX < stageLeft) {
this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY;
}
var curJ = Math.floor(this.centerX / (w + GAP));
var curI = Math.floor(this.centerY / (h + GAP));
this.picturesWrapper.addChild(this.guideHole);
if (0 <= curJ && curJ < (MAX_COL) && 0 <= curI && curI < (MAX_ROW)) {
var index = getIndexFromRC(curI, curJ, MAX_COL);
var dropPic = this.pictures[index];
var dropPicX = dropPic.x + stageLeft;
var dropPicy = dropPic.y + stageTop;
dropPic.x = this.distanceX;
dropPic.y = this.distanceY;
this.dragPic.x = dropPicX - stageLeft;
this.dragPic.y = dropPicy - stageTop;
var dropPicIndex = this.pictures.indexOf(dropPic);
var dragPicIndex = this.pictures.indexOf(this.dragPic);
this.pictures[dropPicIndex] = this.dragPic;
this.pictures[dragPicIndex] = dropPic;
if (dragPicIndex === dropPicIndex) {
GameView.prototype.stageOnUp = function () {
if (GAME_TIME > 0) {
var stageLeft = (750 - props.W) / 2;
var stageTop = (this.stage.height - props.H) / 2;
this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
if (this.centerY < stageTop || this.centerX < stageLeft) {
this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY;
}
var result = true;
for (var j = 0; j < this.rightList.length; j++) {
if (this.rightList[j] != this.pictures[j]) {
result = false;
break;
var curJ = Math.floor(this.centerX / (w + GAP));
var curI = Math.floor(this.centerY / (h + GAP));
this.picturesWrapper.addChild(this.guideHole);
if (0 <= curJ && curJ < MAX_COL && 0 <= curI && curI < MAX_ROW) {
var index = getIndexFromRC(curI, curJ, MAX_COL);
var dropPic = this.pictures[index];
var dropPicX = dropPic.x + stageLeft;
var dropPicy = dropPic.y + stageTop;
dropPic.x = this.distanceX;
dropPic.y = this.distanceY;
this.dragPic.x = dropPicX - stageLeft;
this.dragPic.y = dropPicy - stageTop;
var dropPicIndex = this.pictures.indexOf(dropPic);
var dragPicIndex = this.pictures.indexOf(this.dragPic);
this.pictures[dropPicIndex] = this.dragPic;
this.pictures[dragPicIndex] = dropPic;
if (dragPicIndex === dropPicIndex) {
this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY;
}
var result = true;
for (var j = 0; j < this.rightList.length; j++) {
if (this.rightList[j] != this.pictures[j]) {
result = false;
break;
}
}
if (result) {
this.onSuccess();
}
}
if (result) {
this.onSuccess();
else {
this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY;
}
}
else {
this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY;
}
};
GameView.prototype.onSuccess = function () {
console.log('拼图成功!');
engine.globalEvent.dispatchEvent('pictures-game-success', { time: GAME_TIME });
console.log("拼图成功!");
engine.globalEvent.dispatchEvent("pictures-game-success", {
time: GAME_TIME,
});
this.stop();
};
GameView.prototype.onMove = function (e) {
this.dragPic.x = e.stageX - this.localPicX - (750 - props.W) / 2;
this.dragPic.y = e.stageY - this.localPicY - (this.stage.height - props.H) / 2;
this.dragPic.y =
e.stageY - this.localPicY - (this.stage.height - props.H) / 2;
this.centerX = this.dragPic.x + w / 2;
this.centerY = this.dragPic.y + h / 2;
console.log(this.centerX, this.centerY, "center");
};
return GameView;
}(engine.Container));
//# sourceMappingURL=GameView.js.map
var GameWrapper = (function (_super) {
tslib.__extends(GameWrapper, _super);
......
This diff is collapsed.
......@@ -40,7 +40,7 @@
"GAME_TIME": {
"alias": "游戏时间",
"type": "number",
"default": 50
"default": 5
}
},
......
......@@ -19,11 +19,13 @@ let GAME_TIME;
let w;
// 每张图片高
let h;
export default class GameView extends engine.Container {
private _timer;
private _timeCounter = 0;
start() {
if (!this.guideHole) {
this.guideHole = new engine.Image();
this.guideHole.source = 'asset://' + props.blockUrl;
......@@ -94,6 +96,7 @@ export default class GameView extends engine.Container {
});
if (this.getSecond() == 0) {
GAME_TIME = props.GAME_TIME
this.stop();
engine.globalEvent.dispatchEvent('pictures-game-fail', {
reason: 1
......@@ -121,12 +124,20 @@ export default class GameView extends engine.Container {
}
stop() {
GAME_TIME = props.GAME_TIME
// GAME_TIME = props.GAME_TIME
clearInterval(this._timer);
let len = this.pictures.length;
for(let i=0;i<len;i++){
this.pictures[i].removeAllEventListener();
}
this.stage.removeEventListener(
engine.MouseEvent.MOUSE_UP,
this.stageOnUp,
this
);
}
constructor() {
......@@ -216,22 +227,12 @@ export default class GameView extends engine.Container {
this.distanceY = this.dragPic.y;
// 最开始点击的图片的索引值
// this.indexI = this.distanceX / (w + GAP);
// this.indexJ = this.distanceY / (h + GAP);
// this.index = (this.indexI - 1) * MAX_COL + this.indexJ;
this.indexJ = Math.floor((this.distanceX) / (w + GAP));
this.indexI = Math.floor((this.distanceY) / (h + GAP));
this.index = (this.indexI) * MAX_COL + this.indexJ;
// 图片的中心位置
// this.centerX = e.clientX + w / 2;
// this.centerY = e.clientY + h / 2;
// this.centerX = Math.floor(e.clientX / w) * w + w / 2;
// this.centerY = Math.floor(e.clientY / h) * h + h / 2;
......@@ -275,15 +276,14 @@ export default class GameView extends engine.Container {
this.dragPic.x = this.distanceX ;
this.dragPic.y = this.distanceY ;
}
// 判断图片是否进入另一张图片的范围内
// 要交换的图片第几行第几列
let curJ = Math.floor(this.centerX / (w + GAP));
let curI = Math.floor(this.centerY / (h + GAP));
this.picturesWrapper.addChild(this.guideHole);
// 判断图片是否进入另一张图片的范围内
// 要交换的图片第几行第几列
// 点击图片的位置
......@@ -343,19 +343,17 @@ export default class GameView extends engine.Container {
console.log('拼图成功!');
engine.globalEvent.dispatchEvent('pictures-game-success', { time: GAME_TIME });
this.stop();
}
onMove(e: engine.MouseEvent) {
// 当前图片的位置
this.dragPic.x = e.stageX - this.localPicX - (750 - props.W) / 2;
this.dragPic.y = e.stageY - this.localPicY - (this.stage.height - props.H) / 2;
// console.log('fuck on this.stage.height', this.stage.height)
// console.log(this.dragPic.x, this.dragPic.y)
// 当前图片的中心位置
this.centerX = this.dragPic.x + w / 2;
this.centerY = this.dragPic.y + h / 2;
console.log(this.centerX,this.centerY,"center")
}
// onClk(e){
......
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