消除游戏解析

来源:互联网 发布:域名后缀cc 编辑:程序博客网 时间:2024/04/30 22:03
var touchIndex = event.getUserData()    cc.log(touchIndex, this.cellArr)  //  cc.p(9,4)    var arr = this.checkPoint(touchIndex)    cc.log('第一次检测周围-----------')    TracePointArray(arr)    this.updateCellByArr(arr)    cc.log('第二次检测周围-----------')    for(var i = 0 ; i<GameData.W_NUM*2;i++){        var arr1 = arr.slice()        for(var index in arr){            var po = arr[index]            //arr1 = arr1.concat(this.checkPoint(po))            arr1 = this.filterDelSame(arr1, this.checkPoint(po))        }        TracePointArray(arr1)        this.updateCellByArr(arr1)        var oldLen = arr.length        arr = arr1        if(arr.length == oldLen) break    }    //获取到了颜色相同的数组    this.cellFallDown(arr)},checkPoint:function(touchIndex){//根据一个点检测周围符合情况的点 检测周围4个符合条件的点 返回数组    var checkArr = [cc.p(-1,0),cc.p(1,0),cc.p(0,-1),cc.p(0,1)]    var arr = []    for(var index in checkArr){        var arrayIndex = checkArr[index]        var tempPo = cc.pAdd(touchIndex, arrayIndex)        if(this.checkNeighbor(tempPo, touchIndex)){            arr.push(tempPo)        }    }    return arr;},checkNeighbor:function(po, targetPo){    //根据po的下标是否越界  返回true 或 false    if(po.x < 0 || po.y<0|| po.x > GameData.W_NUM - 1 || po.y>GameData.H_NUM - 1){        return false    }    if(this.cellArr[po.x][po.y] == null || this.cellArr[targetPo.x][targetPo.y] == null) return false    return this.cellArr[po.x][po.y].type == this.cellArr[targetPo.x][targetPo.y].type},
0 0
原创粉丝点击