Commit 6d9121cd authored by 汪欢's avatar 汪欢

拼图0.2

parent 53727adb
......@@ -79,7 +79,6 @@
function GameView() {
var _this = _super.call(this) || this;
_this._timeCounter = 0;
_this.countTime = 10;
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
return _this;
}
......@@ -106,10 +105,12 @@
}
this._timer = setInterval(function () {
_this.onTimer();
}, 1000);
}, 10);
};
GameView.prototype.onTimer = function () {
this._timeCounter++;
this._timeCounter += 0.01;
this._timeCounter = this.afterPointTwo(this._timeCounter);
console.log(this._timeCounter);
engine.globalEvent.dispatchEvent('pictures-time-update', {
second: this.getSecond(),
});
......@@ -120,6 +121,14 @@
});
}
};
GameView.prototype.afterPointTwo = function (n) {
var floatN = parseFloat(n);
if (isNaN(floatN)) {
return;
}
floatN = Math.round(floatN * 100) / 100;
return floatN;
};
GameView.prototype.getSecond = function () {
return GAME_TIME - this._timeCounter;
};
......@@ -174,6 +183,10 @@
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]) {
......@@ -185,6 +198,10 @@
this.onSuccess();
}
}
else {
this.dragPic.x = this.distanceX;
this.dragPic.y = this.distanceY;
}
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
};
GameView.prototype.onSuccess = function () {
......
This diff is collapsed.
......@@ -5,12 +5,12 @@
"MAX_COL": {
"alias": "图片分成几列",
"type": "number",
"default": 2
"default": 3
},
"MAX_ROW": {
"alias": "图片分成几行",
"type": "number",
"default": 2
"default": 3
},
"W": {
"alias": "图片的宽度",
......@@ -30,7 +30,7 @@
"GAME_TIME": {
"alias": "游戏时间",
"type": "number",
"default": 10
"default": 20
}
},
......
......@@ -21,6 +21,9 @@ export default class GameView extends engine.Container {
private _timer;
private _timeCounter = 0;
// 倒计时时间
// private countTime = 20;
start() {
console.log('on start')
engine.globalEvent.dispatchEvent('pictures-time-update', {
......@@ -53,12 +56,17 @@ export default class GameView extends engine.Container {
this._timer = setInterval(() => {
this.onTimer();
}, 1000)
}, 10)
}
onTimer() {
this._timeCounter++;
// this._timeCounter++;
this._timeCounter += 0.01;
this._timeCounter = this.afterPointTwo(this._timeCounter);
// this._timeCounter = Math.floor((this._timeCounter + 0.1) * 10) / 10;
console.log(this._timeCounter)
engine.globalEvent.dispatchEvent('pictures-time-update', {
second: this.getSecond(),
});
......@@ -71,11 +79,23 @@ export default class GameView extends engine.Container {
}
}
afterPointTwo(n){
var floatN = parseFloat(n);
if(isNaN(floatN)){
return ;
}
floatN = Math.round(floatN * 100) /100;
return floatN;
}
getSecond() {
return GAME_TIME - this._timeCounter;
// return GAME_TIME - this.countTime;
}
stop() {
// this.countTime = 0
this._timeCounter = 0;
clearInterval(this._timer);
}
......@@ -105,8 +125,7 @@ export default class GameView extends engine.Container {
indexJ: number;
rightList: engine.Sprite[];
// 倒计时时间
countTime = 10;
private picturesWrapper: engine.Sprite;
......@@ -208,6 +227,12 @@ export default class GameView extends engine.Container {
this.pictures[dropPicIndex] = this.dragPic;
this.pictures[dragPicIndex] = dropPic;
// 图片还是在原来的位置
if(dragPicIndex === dropPicIndex){
this.dragPic.x = this.distanceX
this.dragPic.y = this.distanceY
}
let result = true;
for (let j = 0; j < this.rightList.length; j++) {
if (this.rightList[j] != this.pictures[j]) {
......@@ -220,6 +245,9 @@ export default class GameView extends engine.Container {
this.onSuccess();
}
}else{
this.dragPic.x = this.distanceX
this.dragPic.y = this.distanceY
}
this.stage.removeEventListener(
......
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