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

拼图0.2

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