var that = this; //相邻块的交换、相邻的块改变点击状态、改变点击的块的形态 this.touchListener = cc.eventManager.addCustomListener("checkClick", function (event) { var box = event.getUserData(); cc.log(box.arrindex.x, box.arrindex.y); if (that.oldCell == null) { that.oldCell = box; that.oldCell.opacity = 100 } else { var o = cc.p(box.arrindex.x, box.arrindex.y); var a = cc.p(that.oldCell.arrindex.x + 1, that.oldCell.arrindex.y); var b = cc.p(that.oldCell.arrindex.x - 1, that.oldCell.arrindex.y); var c = cc.p(that.oldCell.arrindex.x, that.oldCell.arrindex.y + 1); var d = cc.p(that.oldCell.arrindex.x, that.oldCell.arrindex.y - 1); if (o.x == a.x && o.y == a.y || o.x == b.x && o.y == b.y || o.x == c.x && o.y == c.y || o.x == d.x && o.y == d.y) { that.oldCell.opacity = 255; that.exchange (box, that.oldCell); that.oldCell = null } else if (box.opacity < 255) { box.opacity = 255; that.oldCell = null } else { that.oldCell.opacity = 255; box.opacity = 100; that.oldCell = box } } }) }, //让可以三消的数组中元素不重复 filterDelSame: function (arr1, arr2) { var returnArr = arr1.concat(arr2); for (var i = 0; i < returnArr.length; i++) { var nowPo = returnArr[i]; for (var j = i + 1; j < returnArr.length; j++) { if (cc.pSameAs(returnArr[j], nowPo)) { returnArr.splice(j, 1); j-- } } } return returnArr }, //相邻块交换后判断是否可以三消 exchange : function (text1,text2) { var a = this.Arr[text1.arrindex.x][text1.arrindex.y]; this.Arr[text1.arrindex.x][text1.arrindex.y] = this.Arr[text2.arrindex.x][text2.arrindex.y]; this.Arr[text2.arrindex.x][text2.arrindex.y] = a; var moveTo = cc.moveTo(0.5, cc.p(text2)); text1.runAction(moveTo); var moveTo = cc.moveTo(0.5, cc.p(text1)); text2.runAction(moveTo); var by = null; by = text1.arrindex; text1.arrindex = text2.arrindex; text2.arrindex = by; text1.gengxing(text1.arrindex); text2.gengxing(text2.arrindex); var tp = this.linkLength(); if (tp == false) { this.scheduleOnce(function () { var moveTo = cc.moveTo(0.5, text1); text2.runAction(moveTo); var moveTo = cc.moveTo(0.5, text2); text1.runAction(moveTo); var by = null; by = text1.arrindex; text1.arrindex = text2.arrindex; text2.arrindex = by; text1.gengxing(text1.arrindex); text2.gengxing(text2.arrindex) }, 1) } else { this.scheduleOnce(function (){ this.Drop (tp) },0.51) } },