Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 91629

在Git上找到了一个连连看游戏,但感觉算法有问题?

$
0
0

@758482981 写道:

https://github.com/yuyuzhang/CocosCreator-LianLianKan
部分消除不了,小白正在尝试算法改进,求教?
//判断两个是否相邻
isBeside:function(x1,x2,y1,y2,t_arrary){
if(Math.abs(x1-x2) == 1 && y1 == y2)
return true;
else if(Math.abs(y1-y2) == 1 && x1 == x2)
return true;
else
return false;
},
//判断是否在一个线上
isLine:function(x1,x2,y1,y2,t_arrary){
var self=this;

    if(self.isBeside(x1, x2, y1, y2, t_arrary))   
    return true;
    if(x1 === x2){
        var Ymin=Math.min(y1,y2);
        var Ymax=Math.max(y1,y2);
        for(Ymin + 1;Ymin < Ymax;Ymin++){
            if(self.imageList[Ymin*self.line + x1].getComponent('pic').isempty === false)
            {
                return false;
            }
        }
        return true;
    }
    if(y1 === y2){
         var Xmin=Math.min(x1,x2) ;
         var Xmax=Math.max(x1,x2);
        for(Xmin;Xmin<Xmax;Xmin++){
           if(self.imageList[y1*self.line+Xmin].getComponent('pic').isempty === false){
            return false;
           }
        }
        return true;
    }
    return false;
},
//判断能否隔空连
isOnedir:function(x1,x2,y1,y2,t_arrary){

    var self=this;

    var i=0;
    for(i;i < self.line; i++){
        if(i!= x1 && self.imageList[y1*self.line + i].getComponent('pic').isempty==true){
            if(self.isLine(i,x2,y1,y2,t_arrary)&&self.isLine(x1, i, y1, y2, t_arrary))
           //if(self.isLine(i,x2,y1,y2,t_arrary))

            return true;
            }
        if(i!= y1 && self.imageList[self.line * i + x1].getComponent('pic').isempty==true){
          if(self.isLine(x1,x2,i,y2,t_arrary)&&self.isLine(x1, x1, y1, i, t_arrary))

             return true;
        }
    }
    // for(var i =self.line - 1;i > -1; i--){
    //     if(i!= x1 && self.imageList[y1*self.line + i].getComponent('pic').isempty==true){
    //         if(self.isLine(i,x2,y1,y2,t_arrary)&&self.isLine(x1, i, y1, y2, t_arrary))
    //         //if(self.isLine(i,x2,y1,y2,t_arrary))
    //         return true;
    //         }
    //     if(i!= y1 && self.imageList[self.line * i + x1].getComponent('pic').isempty==true){
    //       if(self.isLine(x1,x2,i,y2,t_arrary)&&self.isLine(x1, x1, y1, i, t_arrary))

    //          return true;
    //     }
    // }
    return false;
},

帖子: 2

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 91629

Latest Images

Trending Articles

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>