Commit 7f4430e2 authored by zjz1994's avatar zjz1994

消消乐暂存

parent 1c884ff1
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -4,6 +4,16 @@ ...@@ -4,6 +4,16 @@
(global = global || self, global.xiaoxiaole = factory(global.tslib)); (global = global || self, global.xiaoxiaole = factory(global.tslib));
}(this, (function (tslib) { 'use strict'; }(this, (function (tslib) { 'use strict';
var props = {};
function prepareProps() {
var metaProps = getProps();
engine.injectProp(props, metaProps);
}
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
function getTexture(uuid) { function getTexture(uuid) {
return engine.Texture.from(getAssetByUUID(uuid).uuid); return engine.Texture.from(getAssetByUUID(uuid).uuid);
} }
...@@ -286,10 +296,25 @@ ...@@ -286,10 +296,25 @@
_this.homey = -20; _this.homey = -20;
_this.ination = false; _this.ination = false;
_this.canation = true; _this.canation = true;
_this.score = 0; _this._gametime = 60;
_this._gamestat = 2;
_this._score = 0;
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this); _this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
return _this; return _this;
} }
Object.defineProperty(GameView.prototype, "gamestat", {
get: function () {
return this._gamestat;
},
set: function (stat) {
this._gamestat = stat;
if (stat == 2) {
this.changeEnable(false);
}
},
enumerable: true,
configurable: true
});
GameView.prototype.setup = function () { GameView.prototype.setup = function () {
MapData.initPoolEle(); MapData.initPoolEle();
this.selectimg = new engine.Image(getTextureByName("选中框")); this.selectimg = new engine.Image(getTextureByName("选中框"));
...@@ -333,35 +358,68 @@ ...@@ -333,35 +358,68 @@
this.lastframeTime = Date.now(); this.lastframeTime = Date.now();
this.lastatime = Date.now(); this.lastatime = Date.now();
this.addEventListener(engine.Event.ENTER_FRAME, this.onUpdate, this); this.addEventListener(engine.Event.ENTER_FRAME, this.onUpdate, this);
var testbtn = new engine.Label();
testbtn.text = "reset";
testbtn.size = 56;
testbtn.width = 200;
testbtn.height = 100;
this.addChild(testbtn);
testbtn.y = 900;
testbtn.fillColor = "red";
testbtn.addEventListener(engine.MouseEvent.CLICK, this.reset, this);
}; };
GameView.prototype.playComp = function () { GameView.prototype.playComp = function () {
this.homeimg.stop(1); this.homeimg.stop(1);
}; };
GameView.prototype.init = function () { GameView.prototype.init = function (time, level) {
console.log("gameview-init", time, level);
this.score = 0; this.score = 0;
this.gametime = time;
this.initContainer(); this.initContainer();
}; };
GameView.prototype.reset = function () { Object.defineProperty(GameView.prototype, "score", {
get: function () {
return this._score;
},
set: function (num) {
this._score = num;
engine.globalEvent.dispatchEvent('game-score-update', { score: this._score });
},
enumerable: true,
configurable: true
});
Object.defineProperty(GameView.prototype, "gametime", {
get: function () {
return this._gametime;
},
set: function (time) {
var lshowtime = Math.round(this._gametime);
var nshowtime = Math.round(time);
if (lshowtime != nshowtime) {
engine.globalEvent.dispatchEvent('game-time-update', { time: nshowtime });
if (nshowtime <= 0) {
this.gameOver();
}
}
this._gametime = time;
},
enumerable: true,
configurable: true
});
GameView.prototype.gameOver = function () {
this.gamestat = 2;
this.unShowEleAttion();
this.anicontainer.removeChild(this.selectimg);
engine.globalEvent.dispatchEvent("game-over", {
score: this.score
});
};
GameView.prototype.reset = function (time, level) {
return tslib.__awaiter(this, void 0, void 0, function () { return tslib.__awaiter(this, void 0, void 0, function () {
var key, rcname, rcele, rcelex, rceley, rcetype, fallpro, testdata; var key, rcname, rcele, rcelex, rceley, rcetype, fallpro, testdata;
return tslib.__generator(this, function (_a) { return tslib.__generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
console.log("gameview-reset", time, level);
this.anicontainer.removeChild(this.selectimg); this.anicontainer.removeChild(this.selectimg);
this.selectArr = new Array(); this.selectArr = new Array();
this.gametime = time;
this.changeEnable(false); this.changeEnable(false);
for (key in this.lattices) { for (key in this.lattices) {
rcname = this.lattices[key]; rcname = this.lattices[key];
rcele = this.container.getChildByName(rcname); rcele = this.container.getChildByName(rcname);
if (rcele) {
rcelex = rcele.x; rcelex = rcele.x;
rceley = rcele.y; rceley = rcele.y;
rcetype = rcele.type; rcetype = rcele.type;
...@@ -369,6 +427,7 @@ ...@@ -369,6 +427,7 @@
this.lattices[key] = "empty"; this.lattices[key] = "empty";
this.goDisplayAni(rcetype, rcelex, rceley); this.goDisplayAni(rcetype, rcelex, rceley);
} }
}
fallpro = new Promise(function (res) { fallpro = new Promise(function (res) {
setTimeout(function () { setTimeout(function () {
res(); res();
...@@ -392,13 +451,19 @@ ...@@ -392,13 +451,19 @@
}); });
}; };
GameView.prototype.start = function () { GameView.prototype.start = function () {
this.gamestat = 1;
}; };
GameView.prototype.onUpdate = function () { GameView.prototype.onUpdate = function () {
var ntime = Date.now(); var ntime = Date.now();
if (this.gamestat == 1) {
var passtime = ntime - this.lastframeTime; var passtime = ntime - this.lastframeTime;
if (ntime - this.lastatime >= 5000 && !this.ination && this.canation && this.selectArr.length == 0) { if (ntime - this.lastatime >= 5000 && !this.ination && this.canation && this.selectArr.length == 0) {
this.attionEliShow(); this.attionEliShow();
} }
if (this.gametime && this.gametime > 0) {
this.gametime -= passtime / 1000;
}
}
if (this.homeimg) { if (this.homeimg) {
var curframe = this.homeimg.currentFrame; var curframe = this.homeimg.currentFrame;
if (curframe == this.homeimg.totalFrames) { if (curframe == this.homeimg.totalFrames) {
...@@ -445,21 +510,34 @@ ...@@ -445,21 +510,34 @@
this.setLatticeEleRc(rcidx); this.setLatticeEleRc(rcidx);
} }
} }
this.checkInit();
};
GameView.prototype.checkInit = function () {
this.checkEliminate(); this.checkEliminate();
this.fall(); if (this.eliminateArr.length > 0) {
return this.eliminate();
}
else {
this.selectArr = new Array();
var isdiedata = this.attionEliminate();
if (isdiedata && isdiedata.length == 2) {
this.changeEnable(true);
}
else {
this.solveDieMap();
}
}
}; };
GameView.prototype.setLatticeEleRc = function (rcidx) { GameView.prototype.setLatticeEleRc = function (rcidx) {
var rename = this.lattices[rcidx]; var rename = this.lattices[rcidx];
var rcnode = this.container.getChildByName(rename); var rcnode = this.container.getChildByName(rename);
if (rcnode) {
var er = Number(rcidx.split("_")[0]); var er = Number(rcidx.split("_")[0]);
var ec = Number(rcidx.split("_")[1]); var ec = Number(rcidx.split("_")[1]);
rcnode.setrc(er, ec); rcnode.setrc(er, ec);
}
}; };
GameView.prototype.selectele = function (e) { GameView.prototype.unShowEleAttion = function () {
var data = e.data;
var sr = data.r;
var sc = data.c;
var sname = sr + "_" + sc;
if (this.ination) { if (this.ination) {
this.ination = false; this.ination = false;
this.lastatime = Date.now(); this.lastatime = Date.now();
...@@ -469,6 +547,10 @@ ...@@ -469,6 +547,10 @@
var atname2 = this.lattices[arrcidx2]; var atname2 = this.lattices[arrcidx2];
var atnode1 = this.container.getChildByName(atname1); var atnode1 = this.container.getChildByName(atname1);
var atnode2 = this.container.getChildByName(atname2); var atnode2 = this.container.getChildByName(atname2);
if (!atnode1 || !atnode2) {
this.attiondata = new Array();
return;
}
var atpos1 = MapData.getRCPos(arrcidx1.split("_")[0], arrcidx1.split("_")[1]); var atpos1 = MapData.getRCPos(arrcidx1.split("_")[0], arrcidx1.split("_")[1]);
var atpos2 = MapData.getRCPos(arrcidx2.split("_")[0], arrcidx2.split("_")[1]); var atpos2 = MapData.getRCPos(arrcidx2.split("_")[0], arrcidx2.split("_")[1]);
engine.Tween.removeTweens(atnode1); engine.Tween.removeTweens(atnode1);
...@@ -478,6 +560,13 @@ ...@@ -478,6 +560,13 @@
atnode2.x = atpos2[0]; atnode2.x = atpos2[0];
atnode2.y = atpos2[1]; atnode2.y = atpos2[1];
} }
};
GameView.prototype.selectele = function (e) {
var data = e.data;
var sr = data.r;
var sc = data.c;
var sname = sr + "_" + sc;
this.unShowEleAttion();
if (this.selectArr.length == 0) { if (this.selectArr.length == 0) {
this.selectArr.push(sname); this.selectArr.push(sname);
} }
...@@ -529,6 +618,10 @@ ...@@ -529,6 +618,10 @@
this.checkEliminate(); this.checkEliminate();
var snode1 = this.container.getChildByName(sename1); var snode1 = this.container.getChildByName(sename1);
var snode2 = this.container.getChildByName(sename2); var snode2 = this.container.getChildByName(sename2);
if (!snode1 || !snode2) {
this.selectArr = new Array();
return;
}
var snode1x = snode1.x; var snode1x = snode1.x;
var snode1y = snode1.y; var snode1y = snode1.y;
var snode2x = snode2.x; var snode2x = snode2.x;
...@@ -580,17 +673,33 @@ ...@@ -580,17 +673,33 @@
}; };
GameView.prototype.eliminate = function () { GameView.prototype.eliminate = function () {
return tslib.__awaiter(this, void 0, void 0, function () { return tslib.__awaiter(this, void 0, void 0, function () {
var i, ielidata, ielidxname, ielitype, ieliname, ielinode, ielix, ieliy, ietype; var i, ielidata1, ielileng, addscore, j, ielidata, ielidxname, ielitype, ieliname, ielinode, ielix, ieliy, ietype;
return tslib.__generator(this, function (_a) { return tslib.__generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
console.log(JSON.stringify(this.eliminateArr));
for (i = 0; i < this.eliminateArr.length; i++) { for (i = 0; i < this.eliminateArr.length; i++) {
ielidata = this.eliminateArr[i]; ielidata1 = this.eliminateArr[i];
ielileng = ielidata1.length;
addscore = 0;
if (ielileng == 3) {
addscore = props.threeEscore;
}
else if (ielileng == 4) {
addscore = props.fourEscore;
}
else {
addscore = props.moreEscore;
}
this.score += addscore * ielileng;
for (j = 0; j < ielidata1.length; j++) {
ielidata = ielidata1[j];
ielidxname = ielidata.idxname; ielidxname = ielidata.idxname;
ielitype = ielidata.type; ielitype = ielidata.type;
ieliname = this.lattices[ielidxname]; ieliname = this.lattices[ielidxname];
ielinode = this.container.getChildByName(ieliname); ielinode = this.container.getChildByName(ieliname);
if (!ielinode) {
continue;
}
ielix = ielinode.x; ielix = ielinode.x;
ieliy = ielinode.y; ieliy = ielinode.y;
ietype = ielinode.type; ietype = ielinode.type;
...@@ -599,6 +708,7 @@ ...@@ -599,6 +708,7 @@
this.lattices[ielidxname] = "empty"; this.lattices[ielidxname] = "empty";
this.goHomeAni(ielitype, ielix, ieliy); this.goHomeAni(ielitype, ielix, ieliy);
} }
}
return [4, new Promise(function (res) { return [4, new Promise(function (res) {
setTimeout(function () { setTimeout(function () {
res(); res();
...@@ -673,6 +783,9 @@ ...@@ -673,6 +783,9 @@
var ftcol = fdata.tcol; var ftcol = fdata.tcol;
var ftpos = MapData.getRCPos(ftrow, ftcol); var ftpos = MapData.getRCPos(ftrow, ftcol);
var frcnode = this_1.container.getChildByName(frcname); var frcnode = this_1.container.getChildByName(frcname);
if (!frcnode) {
return "continue";
}
var nepos = [frcnode.x, frcnode.y]; var nepos = [frcnode.x, frcnode.y];
var fdis = MapData.getDistance(ftpos, nepos); var fdis = MapData.getDistance(ftpos, nepos);
var ftime = Math.ceil((fdis / MapData.anispeed) * 1000); var ftime = Math.ceil((fdis / MapData.anispeed) * 1000);
...@@ -760,15 +873,28 @@ ...@@ -760,15 +873,28 @@
aniele.flyToHome(this.tanix, this.taniy, anitime); aniele.flyToHome(this.tanix, this.taniy, anitime);
}; };
GameView.prototype.changeEnable = function (v) { GameView.prototype.changeEnable = function (v) {
var changeable = false;
if (this.gamestat == 1) {
changeable = true;
}
else {
if (!v) {
changeable = true;
}
}
if (changeable) {
for (var key in this.lattices) { for (var key in this.lattices) {
var kname = this.lattices[key]; var kname = this.lattices[key];
var ele = this.container.getChildByName(kname); var ele = this.container.getChildByName(kname);
if (ele) {
ele.touch = v; ele.touch = v;
} }
}
if (v) { if (v) {
this.lastatime = Date.now(); this.lastatime = Date.now();
this.ination = false; this.ination = false;
} }
}
this.canation = v; this.canation = v;
}; };
GameView.prototype.attionEliShow = function () { GameView.prototype.attionEliShow = function () {
...@@ -780,6 +906,9 @@ ...@@ -780,6 +906,9 @@
var atname2 = this.lattices[attiondata[1]]; var atname2 = this.lattices[attiondata[1]];
var atnode1 = this.container.getChildByName(atname1); var atnode1 = this.container.getChildByName(atname1);
var atnode2 = this.container.getChildByName(atname2); var atnode2 = this.container.getChildByName(atname2);
if (!atnode1 || !atnode2) {
return;
}
var atx1 = atnode1.x; var atx1 = atnode1.x;
var aty1 = atnode1.y; var aty1 = atnode1.y;
var atx2 = atnode2.x; var atx2 = atnode2.x;
...@@ -814,6 +943,9 @@ ...@@ -814,6 +943,9 @@
} }
}; };
GameView.prototype.solveDieMap = function () { GameView.prototype.solveDieMap = function () {
if (this.gamestat != 1) {
return;
}
this.changeEnable(false); this.changeEnable(false);
var elearr = new Array(); var elearr = new Array();
for (var key in this.lattices) { for (var key in this.lattices) {
...@@ -843,6 +975,9 @@ ...@@ -843,6 +975,9 @@
for (key in this.lattices) { for (key in this.lattices) {
keyval = this.lattices[key]; keyval = this.lattices[key];
keynode = this.container.getChildByName(keyval); keynode = this.container.getChildByName(keyval);
if (!keynode) {
continue;
}
keynodex = keynode.x; keynodex = keynode.x;
keynodey = keynode.y; keynodey = keynode.y;
tpos = MapData.getRCPos(key.split("_")[0], key.split("_")[1]); tpos = MapData.getRCPos(key.split("_")[0], key.split("_")[1]);
...@@ -1134,29 +1269,61 @@ ...@@ -1134,29 +1269,61 @@
var rc = r + "_" + c; var rc = r + "_" + c;
var elename = this.lattices[rc]; var elename = this.lattices[rc];
var ele = this.container.getChildByName(elename); var ele = this.container.getChildByName(elename);
if (ele) {
var eletype = ele.type; var eletype = ele.type;
return eletype; return eletype;
}
}; };
GameView.prototype.checkAddEli = function (etype, earr) { GameView.prototype.checkAddEli = function (etype, earr) {
console.log(JSON.stringify(earr)); var addnew = true;
for (var e = 0; e < earr.length; e++) { var inaidx;
var ename = earr[e]; for (var i1 = 0; i1 < this.eliminateArr.length; i1++) {
var needadd = true; var i1data = this.eliminateArr[i1];
for (var i = 0; i < this.eliminateArr.length; i++) { for (var i2 = 0; i2 < i1data.length; i2++) {
var ielidata = this.eliminateArr[i]; var i2data = i1data[i2];
var ielidxname = ielidata.idxname; var i2eliname = i2data.idxname;
if (ielidxname == ename) { var inidx = earr.indexOf(i2eliname);
needadd = false; if (inidx != -1) {
addnew = false;
break;
}
}
if (!addnew) {
inaidx = i1;
break;
}
}
if (addnew) {
var addarr = new Array();
for (var i1 = 0; i1 < earr.length; i1++) {
var i1name = earr[i1];
addarr.push({
idxname: i1name,
type: etype
});
}
this.eliminateArr.push(addarr);
}
else {
for (var i4 = 0; i4 < earr.length; i4++) {
var i4name = earr[i4];
var addele = true;
for (var i3 = 0; i3 < this.eliminateArr[inaidx].length; i3++) {
var i3data = this.eliminateArr[inaidx][i3];
var i3eliname = i3data.idxname;
if (i3eliname == i4name) {
addele = false;
break; break;
} }
} }
if (needadd) { if (addele) {
this.eliminateArr.push({ this.eliminateArr[inaidx].push({
idxname: ename, idxname: i4name,
type: etype type: etype
}); });
} }
} }
}
}; };
GameView.prototype.getFallRcEle = function (r, c) { GameView.prototype.getFallRcEle = function (r, c) {
for (var fr = r - 1; fr > -1; fr--) { for (var fr = r - 1; fr > -1; fr--) {
...@@ -1184,11 +1351,13 @@ ...@@ -1184,11 +1351,13 @@
engine.globalEvent.addEventListener('game-start', _this.start, _this); engine.globalEvent.addEventListener('game-start', _this.start, _this);
return _this; return _this;
} }
GameWrapper.prototype.init = function () { GameWrapper.prototype.init = function (event) {
this._gameView.init(); console.log("gamewrapper-init", event);
this._gameView.init(event.data.time, event.data.level);
}; };
GameWrapper.prototype.reset = function () { GameWrapper.prototype.reset = function (event) {
this._gameView.reset(); console.log("gamewrapper-reset", event);
this._gameView.reset(event.data.time, event.data.level);
}; };
GameWrapper.prototype.start = function () { GameWrapper.prototype.start = function () {
this._gameView.start(); this._gameView.start();
...@@ -1197,16 +1366,6 @@ ...@@ -1197,16 +1366,6 @@
}(engine.Container)); }(engine.Container));
//# sourceMappingURL=GameWrapper.js.map //# sourceMappingURL=GameWrapper.js.map
var props = {};
function prepareProps() {
var metaProps = getProps();
engine.injectProp(props, metaProps);
}
function injectProps(p) {
engine.injectProp(props, p);
}
//# sourceMappingURL=props.js.map
function index (props) { function index (props) {
prepareProps(); prepareProps();
injectProps(props); injectProps(props);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2,7 +2,21 @@ ...@@ -2,7 +2,21 @@
"name": "消消乐", "name": "消消乐",
"desc": "消消乐模块", "desc": "消消乐模块",
"props": { "props": {
"threeEscore":{
"alias":"三消加分",
"type":"number",
"default":1
},
"fourEscore":{
"alias":"四消加分",
"type":"number",
"default":2
},
"moreEscore":{
"alias":"多消加分",
"type":"number",
"default":3
}
}, },
"assets": [ "assets": [
{ {
......
...@@ -48,7 +48,17 @@ export default class GameView extends engine.Container { ...@@ -48,7 +48,17 @@ export default class GameView extends engine.Container {
ination = false; ination = false;
canation = true; canation = true;
score = 0; _gametime = 60;
_gamestat=2;
set gamestat(stat){//1游戏中,2,游戏外
this._gamestat = stat;
if(stat==2){
this.changeEnable(false);
}
}
get gamestat(){
return this._gamestat;
}
setup() { setup() {
MapData.initPoolEle(); MapData.initPoolEle();
...@@ -107,34 +117,71 @@ export default class GameView extends engine.Container { ...@@ -107,34 +117,71 @@ export default class GameView extends engine.Container {
this.addEventListener(engine.Event.ENTER_FRAME,this.onUpdate,this); this.addEventListener(engine.Event.ENTER_FRAME,this.onUpdate,this);
//测试 //测试
let testbtn = new engine.Label(); // let testbtn = new engine.Label();
testbtn.text = "reset"; // testbtn.text = "reset";
testbtn.size = 56; // testbtn.size = 56;
testbtn.width = 200; // testbtn.width = 200;
testbtn.height = 100; // testbtn.height = 100;
this.addChild(testbtn); // this.addChild(testbtn);
testbtn.y = 900; // testbtn.y = 900;
testbtn.fillColor = "red"; // testbtn.fillColor = "red";
testbtn.addEventListener(engine.MouseEvent.CLICK,this.reset,this); // testbtn.addEventListener(engine.MouseEvent.CLICK,this.reset,this);
} }
playComp(){ playComp(){
this.homeimg.stop(1); this.homeimg.stop(1);
} }
init(){ init(time,level){
console.log("gameview-init",time,level);
this.score = 0; this.score = 0;
this.gametime = time;
this.initContainer(); this.initContainer();
} }
_score = 0;
set score(num){
this._score = num;
engine.globalEvent.dispatchEvent('game-score-update',{score:this._score});
}
get score(){
return this._score;
}
set gametime(time){
let lshowtime = Math.round(this._gametime);
let nshowtime = Math.round(time);
if(lshowtime!=nshowtime){
// console.log("倒计时更新",nshowtime);
engine.globalEvent.dispatchEvent('game-time-update',{time:nshowtime});
if(nshowtime<=0){
this.gameOver();
}
}
this._gametime = time;
}
get gametime(){
return this._gametime;
}
gameOver(){
// console.log("游戏结束");
this.gamestat = 2;
this.unShowEleAttion();
this.anicontainer.removeChild(this.selectimg);
engine.globalEvent.dispatchEvent("game-over",{
score:this.score
})
};
levelData; levelData;
async reset(){ async reset(time,level){
console.log("gameview-reset",time,level);
this.anicontainer.removeChild(this.selectimg); this.anicontainer.removeChild(this.selectimg);
this.selectArr = new Array(); this.selectArr = new Array();
this.gametime = time;
this.changeEnable(false); this.changeEnable(false);
for(let key in this.lattices){ for(let key in this.lattices){
let rcname = this.lattices[key]; let rcname = this.lattices[key];
let rcele:Element = this.container.getChildByName(rcname); let rcele:Element = this.container.getChildByName(rcname);
if(rcele){
let rcelex = rcele.x; let rcelex = rcele.x;
let rceley = rcele.y; let rceley = rcele.y;
let rcetype = rcele.type; let rcetype = rcele.type;
...@@ -144,6 +191,7 @@ export default class GameView extends engine.Container { ...@@ -144,6 +191,7 @@ export default class GameView extends engine.Container {
this.goDisplayAni(rcetype,rcelex,rceley); this.goDisplayAni(rcetype,rcelex,rceley);
} }
}
let fallpro = new Promise(res=>{ let fallpro = new Promise(res=>{
setTimeout(function(){ setTimeout(function(){
res(); res();
...@@ -162,14 +210,19 @@ export default class GameView extends engine.Container { ...@@ -162,14 +210,19 @@ export default class GameView extends engine.Container {
this.fall("newlevel"); this.fall("newlevel");
} }
start(){ start(){
this.gamestat = 1;
} }
onUpdate(){ onUpdate(){
let ntime = Date.now(); let ntime = Date.now();
if(this.gamestat==1){
let passtime = ntime - this.lastframeTime; let passtime = ntime - this.lastframeTime;
if(ntime-this.lastatime>=5000&&!this.ination&&this.canation&&this.selectArr.length==0){ if(ntime-this.lastatime>=5000&&!this.ination&&this.canation&&this.selectArr.length==0){
this.attionEliShow(); this.attionEliShow();
} }
if(this.gametime&&this.gametime>0){
this.gametime -= passtime/1000;
}
}
if(this.homeimg){ if(this.homeimg){
let curframe = this.homeimg.currentFrame; let curframe = this.homeimg.currentFrame;
if(curframe==this.homeimg.totalFrames){ if(curframe==this.homeimg.totalFrames){
...@@ -221,23 +274,36 @@ export default class GameView extends engine.Container { ...@@ -221,23 +274,36 @@ export default class GameView extends engine.Container {
} }
} }
//初始化,检测消除,死图
this.checkInit();
}
checkInit(){
this.checkEliminate(); this.checkEliminate();
this.fall(); if(this.eliminateArr.length>0){
return this.eliminate();
}else{//一次操作完毕
this.selectArr = new Array();
let isdiedata = this.attionEliminate();
if(isdiedata&&isdiedata.length==2){//没死
this.changeEnable(true);
}else{//死图处理
this.solveDieMap();
}
//检查死图
}
} }
//关联 //关联
setLatticeEleRc(rcidx){ setLatticeEleRc(rcidx){
let rename = this.lattices[rcidx]; let rename = this.lattices[rcidx];
let rcnode:Element = this.container.getChildByName(rename); let rcnode:Element = this.container.getChildByName(rename);
if(rcnode){
let er = Number(rcidx.split("_")[0]); let er = Number(rcidx.split("_")[0]);
let ec = Number(rcidx.split("_")[1]); let ec = Number(rcidx.split("_")[1]);
rcnode.setrc(er,ec); rcnode.setrc(er,ec);
} }
}
selectele(e:engine.Event){ //取消提示选择
let data = e.data; unShowEleAttion(){
let sr = data.r;
let sc = data.c;
let sname = sr+"_"+sc;
if(this.ination){ if(this.ination){
this.ination = false; this.ination = false;
this.lastatime = Date.now(); this.lastatime = Date.now();
...@@ -247,6 +313,10 @@ export default class GameView extends engine.Container { ...@@ -247,6 +313,10 @@ export default class GameView extends engine.Container {
let atname2 = this.lattices[arrcidx2]; let atname2 = this.lattices[arrcidx2];
let atnode1:Element = this.container.getChildByName(atname1); let atnode1:Element = this.container.getChildByName(atname1);
let atnode2:Element = this.container.getChildByName(atname2); let atnode2:Element = this.container.getChildByName(atname2);
if(!atnode1||!atnode2){
this.attiondata = new Array();
return;
}
let atpos1 = MapData.getRCPos(arrcidx1.split("_")[0],arrcidx1.split("_")[1]); let atpos1 = MapData.getRCPos(arrcidx1.split("_")[0],arrcidx1.split("_")[1]);
let atpos2 = MapData.getRCPos(arrcidx2.split("_")[0],arrcidx2.split("_")[1]); let atpos2 = MapData.getRCPos(arrcidx2.split("_")[0],arrcidx2.split("_")[1]);
...@@ -259,8 +329,16 @@ export default class GameView extends engine.Container { ...@@ -259,8 +329,16 @@ export default class GameView extends engine.Container {
atnode2.x = atpos2[0]; atnode2.x = atpos2[0];
atnode2.y = atpos2[1]; atnode2.y = atpos2[1];
} }
}
//选择元素
selectele(e:engine.Event){
let data = e.data;
let sr = data.r;
let sc = data.c;
let sname = sr+"_"+sc;
this.unShowEleAttion();
if(this.selectArr.length==0){ if(this.selectArr.length==0){
// console.log("选中元素",data); // console.log("选中元素",data);
this.selectArr.push(sname); this.selectArr.push(sname);
...@@ -321,6 +399,10 @@ export default class GameView extends engine.Container { ...@@ -321,6 +399,10 @@ export default class GameView extends engine.Container {
let snode1 = this.container.getChildByName(sename1); let snode1 = this.container.getChildByName(sename1);
let snode2 = this.container.getChildByName(sename2); let snode2 = this.container.getChildByName(sename2);
if(!snode1||!snode2){
this.selectArr = new Array();
return;
}
let snode1x = snode1.x; let snode1x = snode1.x;
let snode1y = snode1.y; let snode1y = snode1.y;
...@@ -378,14 +460,30 @@ export default class GameView extends engine.Container { ...@@ -378,14 +460,30 @@ export default class GameView extends engine.Container {
//消除 //消除
async eliminate(){ async eliminate(){
console.log(JSON.stringify(this.eliminateArr));
for(let i=0;i<this.eliminateArr.length;i++){ for(let i=0;i<this.eliminateArr.length;i++){
let ielidata = this.eliminateArr[i]; let ielidata1 = this.eliminateArr[i];
let ielileng = ielidata1.length;
let addscore = 0;
if(ielileng==3){
addscore = props.threeEscore;
}else if(ielileng==4){
addscore = props.fourEscore;
}else{
addscore = props.moreEscore;
}
// console.log("消除单个加分",addscore);
this.score += addscore*ielileng;
for(let j=0;j<ielidata1.length;j++){
let ielidata = ielidata1[j];
let ielidxname = ielidata.idxname; let ielidxname = ielidata.idxname;
let ielitype = ielidata.type; let ielitype = ielidata.type;
let ieliname = this.lattices[ielidxname]; let ieliname = this.lattices[ielidxname];
let ielinode:Element = this.container.getChildByName(ieliname); let ielinode:Element = this.container.getChildByName(ieliname);
if(!ielinode){
continue;
}
let ielix = ielinode.x; let ielix = ielinode.x;
let ieliy = ielinode.y; let ieliy = ielinode.y;
let ietype = ielinode.type; let ietype = ielinode.type;
...@@ -396,6 +494,7 @@ export default class GameView extends engine.Container { ...@@ -396,6 +494,7 @@ export default class GameView extends engine.Container {
//元素层消除,动画层添加 //元素层消除,动画层添加
this.goHomeAni(ielitype,ielix,ieliy); this.goHomeAni(ielitype,ielix,ieliy);
} }
}
await new Promise(res=>{ await new Promise(res=>{
setTimeout(function(){ setTimeout(function(){
...@@ -466,7 +565,9 @@ export default class GameView extends engine.Container { ...@@ -466,7 +565,9 @@ export default class GameView extends engine.Container {
let ftcol = fdata.tcol; let ftcol = fdata.tcol;
let ftpos = MapData.getRCPos(ftrow,ftcol); let ftpos = MapData.getRCPos(ftrow,ftcol);
let frcnode = this.container.getChildByName(frcname); let frcnode = this.container.getChildByName(frcname);
if(!frcnode){
continue;
}
let nepos = [frcnode.x,frcnode.y]; let nepos = [frcnode.x,frcnode.y];
let fdis = MapData.getDistance(ftpos,nepos); let fdis = MapData.getDistance(ftpos,nepos);
let ftime = Math.ceil((fdis/MapData.anispeed)*1000); let ftime = Math.ceil((fdis/MapData.anispeed)*1000);
...@@ -558,15 +659,28 @@ export default class GameView extends engine.Container { ...@@ -558,15 +659,28 @@ export default class GameView extends engine.Container {
//修改元素点击 //修改元素点击
changeEnable(v:boolean){ changeEnable(v:boolean){
let changeable = false;
if(this.gamestat==1){
changeable = true;
}else{
if(!v){
changeable = true;
}
}
if(changeable){
for(let key in this.lattices){ for(let key in this.lattices){
let kname = this.lattices[key]; let kname = this.lattices[key];
let ele:Element = this.container.getChildByName(kname); let ele:Element = this.container.getChildByName(kname);
if(ele){
ele.touch = v; ele.touch = v;
} }
}
if(v){ if(v){
this.lastatime = Date.now(); this.lastatime = Date.now();
this.ination = false; this.ination = false;
} }
}
this.canation = v; this.canation = v;
} }
...@@ -581,6 +695,10 @@ export default class GameView extends engine.Container { ...@@ -581,6 +695,10 @@ export default class GameView extends engine.Container {
let atnode1:Element = this.container.getChildByName(atname1); let atnode1:Element = this.container.getChildByName(atname1);
let atnode2:Element = this.container.getChildByName(atname2); let atnode2:Element = this.container.getChildByName(atname2);
if(!atnode1||!atnode2){
return;
}
let atx1 = atnode1.x; let atx1 = atnode1.x;
let aty1 = atnode1.y; let aty1 = atnode1.y;
...@@ -621,6 +739,9 @@ export default class GameView extends engine.Container { ...@@ -621,6 +739,9 @@ export default class GameView extends engine.Container {
} }
//死图调整 //死图调整
solveDieMap(){ solveDieMap(){
if(this.gamestat!=1){
return;
}
this.changeEnable(false); this.changeEnable(false);
// console.error("死图调整"); // console.error("死图调整");
// console.log(this.lattices); // console.log(this.lattices);
...@@ -650,6 +771,9 @@ export default class GameView extends engine.Container { ...@@ -650,6 +771,9 @@ export default class GameView extends engine.Container {
for(let key in this.lattices){ for(let key in this.lattices){
let keyval = this.lattices[key]; let keyval = this.lattices[key];
var keynode:Element = this.container.getChildByName(keyval); var keynode:Element = this.container.getChildByName(keyval);
if(!keynode){
continue;
}
let keynodex = keynode.x; let keynodex = keynode.x;
let keynodey = keynode.y; let keynodey = keynode.y;
...@@ -987,30 +1111,59 @@ export default class GameView extends engine.Container { ...@@ -987,30 +1111,59 @@ export default class GameView extends engine.Container {
let rc = r+"_"+c; let rc = r+"_"+c;
let elename = this.lattices[rc]; let elename = this.lattices[rc];
let ele:Element = this.container.getChildByName(elename); let ele:Element = this.container.getChildByName(elename);
if(ele){
let eletype = ele.type; let eletype = ele.type;
return eletype; return eletype;
} }
checkAddEli(etype,earr){ }
console.log(JSON.stringify(earr)); checkAddEli(etype,earr:Array<string>){
for(let e=0;e<earr.length;e++){ let addnew = true;
let ename = earr[e]; let inaidx;
for(let i1=0;i1<this.eliminateArr.length;i1++){
let needadd = true; let i1data = this.eliminateArr[i1];
for(let i=0;i<this.eliminateArr.length;i++){ for(let i2=0;i2<i1data.length;i2++){
let ielidata = this.eliminateArr[i]; let i2data = i1data[i2];
let ielidxname = ielidata.idxname; let i2eliname = i2data.idxname;
if(ielidxname==ename){ let inidx = earr.indexOf(i2eliname);
needadd = false; if(inidx!=-1){
addnew = false;
break; break;
} }
} }
if(needadd){ if(!addnew){
this.eliminateArr.push({ inaidx = i1;
idxname:ename, break;
}
}
if(addnew){
let addarr = new Array();
for(let i1=0;i1<earr.length;i1++){
let i1name = earr[i1];
addarr.push({
idxname:i1name,
type:etype type:etype
}) })
} }
this.eliminateArr.push(addarr);
}else{
for(let i4=0;i4<earr.length;i4++){
let i4name = earr[i4];
let addele = true;
for(let i3=0;i3<this.eliminateArr[inaidx].length;i3++){
let i3data = this.eliminateArr[inaidx][i3];
let i3eliname = i3data.idxname;
if(i3eliname==i4name){
addele = false;
break;
}
}
if(addele){
this.eliminateArr[inaidx].push({
idxname:i4name,
type:etype
})
}
}
} }
} }
//获得这个位置掉落的元素 //获得这个位置掉落的元素
......
...@@ -19,11 +19,13 @@ export class GameWrapper extends engine.Container { ...@@ -19,11 +19,13 @@ export class GameWrapper extends engine.Container {
engine.globalEvent.addEventListener('game-start',this.start,this); engine.globalEvent.addEventListener('game-start',this.start,this);
} }
init(){ init(event:engine.Event){
this._gameView.init(); console.log("gamewrapper-init",event);
this._gameView.init(event.data.time,event.data.level);
} }
reset(){ reset(event:engine.Event){
this._gameView.reset(); console.log("gamewrapper-reset",event);
this._gameView.reset(event.data.time,event.data.level);;
} }
start(){ start(){
this._gameView.start(); this._gameView.start();
......
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