跟着BOY学习--史上最通俗易懂的连连看算法--cocos2d-x 环境下开发

[cpp]  view plain copy
  1.   

兄弟们大家好,本来说好的是星期五出连连看的。不过被我给睡过去了,这些天一直都很瞌睡。不过睡眠好了做事的效率就高。希望兄弟们不要见怪。废话话不多说,首先我先说明说明一下《连连看地图布局之谜》

先上一张图给大家看看

当大家看到这张图片的时候会看到周围一圈对号,这个是我做标记用的,当然 真正的开发游戏过程中 这些对号是不存在的。我这里想给大家说明的是 假如我们的 地图是14*8的 那么其实真正的地图布局应该是16*10 为什么要这么做呢 那是因为我们要让我们所有的路线都从我们规定的方格内经过,不能越界。如果你是14*8 的那么当四边上有可以连通的时候 就要做大量的判断来处理。那么为什么我们不避免这些问题呢。这样我们在规划路线的时候 就不存在了特殊的情况。
   不知道大家是否明白我说的什么意思。如果不懂的话可以给我留言我会给大家回复 解答。
   关于图片的生成我这里说一下 如何保证所有的图片 都是成对出现呢 这里有个前提条件就是我们的地图布局一定要成偶数。那么我们在生出图片的 我们每一次取出一张图片生成两个一模一样的 这样就保证地图里面所有的图片肯定是成对出现的。
  主要代码是这样的

[cpp]  view plain copy
  1. int totalcout=this->row*this->cloum;  
  2.               CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("point.plist","point.png");  
  3.               CCArray* temparry=CCArray::create();  
  4.               // 一次生成两张一样的  
  5.               for (int i=0;i<totalcout/2;i++){  
  6.                       int num=CCRANDOM_0_1()*35;//因为是图片的张数是从0到36张 所以随机从0 到35  
  7.                       CustomSprite*  phit1=  CustomSprite::createWithSpritePicIndex(num,CCSize(picWidth,picHeight));                  
  8.                       CustomSprite*  phit2=  CustomSprite::createWithSpritePicIndex(num,CCSize(picWidth,picHeight));                  
  9.                       temparry->addObject(phit1);  
  10.                       temparry->addObject(phit2);  
  11.               }  

 是不是很简单啊
   至于如何把生成的东西给打乱。这个cocos2d-x 提供了很好用的方法那就是从数组中取出的时候 可以随机去取出。
  下面把整个地图布局的方法给贴出来
[cpp]  view plain copy
  1. bool LLKmapLayer::setUpdateView(){  
  2.         bool isRet=false;  
  3.         do {  
  4.                 //得到需要的总张数  // 一定要是偶数  
  5.                 int totalcout=this->row*this->cloum;  
  6.                 CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("point.plist","point.png");  
  7.                 CCArray* temparry=CCArray::create();  
  8.                 // 一次生成两张一样的  
  9.                 for (int i=0;i<totalcout/2;i++){  
  10.                         int num=CCRANDOM_0_1()*35;//因为是图片的张数是从0到36张 所以随机从0 到35  
  11.                         CustomSprite*  phit1=  CustomSprite::createWithSpritePicIndex(num,CCSize(picWidth,picHeight));                  
  12.                         CustomSprite*  phit2=  CustomSprite::createWithSpritePicIndex(num,CCSize(picWidth,picHeight));                  
  13.                         temparry->addObject(phit1);  
  14.                         temparry->addObject(phit2);  
  15.                 }  
  16.   
  17.                 for(int i=0;i<row+2;i++){  
  18.                         for(int j=0;j<this->cloum+2;j++){  
  19.   
  20.                                 if ((i==0)||(j==0)||(j==cloum+1)||(i==row+1)){  
  21.                                         CustomSprite*  temp=  CustomSprite::createWithSpritePicIndex(0,CCSize(picWidth,picHeight));  
  22.                                         temp->displayCustome();  
  23.                                         temp->setX(j);  
  24.                                         temp->setY(i);  
  25.   
  26.                                         temp->setAnchorPoint(ccp(0,0));  
  27.                                         temp->setPosition(ccp(45*(j-1),51*(i-1)));  
  28.                                                 this->addChild(temp);  
  29.                                         this->totalArray->addObject(temp);  
  30.   
  31.                                 }else {  
  32.                                         CustomSprite* phit=(CustomSprite*)temparry->randomObject();  
  33.                                         temparry->removeObject(phit,false);  
  34.                                         phit->setAnchorPoint(ccp(0,0));  
  35.                                         phit->setPosition(ccp(45*(j-1),51*(i-1)));  
  36.                                         this->addChild(phit);  
  37.                                         llkArray->addObject(phit);  
  38.                                         phit->setX(j);  
  39.                                         phit->setY(i);  
  40.                                         this->totalArray->addObject(phit);  
  41.                                 }  
  42.                         }  
  43.                 }  
  44.                 isRet=true;          
  45.         } while (0);  
  46.         return isRet;  
  47. }  

是不是很少的代码就实现了这个功能了。
下面就开始我们今天的重头戏 那就是连连看的主要算法
首先先说明最简单 那就是一线贯通。


大家看到我画的红线   是连连看中最简单的 两种连接方式 
   只要两张图片 处于同一水平线或者同一垂直线  如果两张图片中没有别的图片间隔就代表可以连通消除了
  主要代码

[cpp]  view plain copy
  1. // 这个是横向检测  
  2. CCArray* LLKAlgorithm::horizon(cocos2d::CCArray* llkArray,cocos2d::CCArray* hitArray){  
  3.         CustomSprite* hit1=(CustomSprite*)hitArray->objectAtIndex(0);// 取出第一个  
  4.         CustomSprite* hit2=(CustomSprite*)hitArray->objectAtIndex(1);// 取出第二个  
  5.         int x1=hit1->getX(); // 得到第一个X 坐标  
  6.         int x2=hit2->getX(); // 得到第二个X 坐标  
  7.         bool isda=x1>x2?true:false;// 得出那个坐标肯后  
  8.         int temp=isda?x1-x2:x2-x1; // 获取两个两个点之间的 间隔  
  9.         CCArray* temparray=CCArray::create();// 记录两个点之间 所经过的点  
  10.   
  11.         if (temp==1){// 表示两个是相邻的两个  
  12.                 temparray->addObject(hit1);  
  13.                 temparray->addObject(hit2);  
  14.         }else {      
  15.   
  16.                 if (isda){  
  17.                         temparray->addObject(hit1);  
  18.                         temparray->addObject(hit2);  
  19.                         for(int i=1;i<temp;i++){  
  20.                                 CustomSprite* hitteim=LLKAlgorithm::getCustByXandY(llkArray,x1-i,hit2->getY());  
  21.                                 // 如果是已经消除的那么 就可以继续查询  
  22.                                 if (!hitteim->getIsEliminate()){  
  23.                                         LLKAlgorithm::removeAllArray(temparray,false);  
  24.                                         break;  
  25.                                 }else {  
  26.                                         temparray->addObject(hitteim);  
  27.                                 }  
  28.                         }  
  29.   
  30.                 }else {  
  31.                         temparray->addObject(hit2);  
  32.                         temparray->addObject(hit1);  
  33.                         for(int i=1;i<temp;i++){  
  34.                                 CustomSprite* hitteim=LLKAlgorithm::getCustByXandY(llkArray,x2-i,hit2->getY());  
  35.                                 // 如果是已经消除的那么 就可以继续查询  
  36.                                 if (!hitteim->getIsEliminate()){  
  37.                                         LLKAlgorithm::removeAllArray(temparray,false);  
  38.                                         break;  
  39.                                 }else {  
  40.                                         temparray->addObject(hitteim);  
  41.                                 }  
  42.                         }  
  43.                 }  
  44.   
  45.         }  
  46.   
  47.   
  48.         return temparray;  
  49.   
  50. }  
  51. //这个是纵向检测  
  52. CCArray*  LLKAlgorithm::vertical(cocos2d::CCArray* llkArray,cocos2d::CCArray* hitArray){  
  53.         CustomSprite* hit1=(CustomSprite*)hitArray->objectAtIndex(0);// 取出第一个  
  54.         CustomSprite* hit2=(CustomSprite*)hitArray->objectAtIndex(1);// 取出第二个  
  55.         int y1=hit1->getY(); // 得到第一个Y 坐标  
  56.         int y2=hit2->getY(); // 得到第二个Y 坐标  
  57.         bool isda=y1>y2?true:false;// 得出那个坐标肯后  
  58.         int temp=isda?y1-y2:y2-y1; // 获取两个两个点之间的 间隔  
  59.         CCArray* temparray=CCArray::create();// 记录两个点之间 所经过的点  
  60.   
  61.         if (temp==1){// 表示两个是相邻的两个  
  62.                 temparray->addObject(hit1);  
  63.                 temparray->addObject(hit2);  
  64.         }else {      
  65.   
  66.                 if (isda){  
  67.                         temparray->addObject(hit1);  
  68.                         temparray->addObject(hit2);  
  69.                         for(int i=1;i<temp;i++){  
  70.                                 CustomSprite* hitteim=LLKAlgorithm::getCustByXandY(llkArray,hit2->getX(),y1-i);  
  71.                                 // 如果是已经消除的那么 就可以继续查询  
  72.                                 if (!hitteim->getIsEliminate()){  
  73.                                         LLKAlgorithm::removeAllArray(temparray,false);  
  74.                                         break;  
  75.                                 }else {  
  76.                                         temparray->addObject(hitteim);  
  77.                                 }  
  78.                         }  
  79.   
  80.                 }else {  
  81.                         temparray->addObject(hit2);  
  82.                         temparray->addObject(hit1);  
  83.                         for(int i=1;i<temp;i++){  
  84.                                 CustomSprite* hitteim=LLKAlgorithm::getCustByXandY(llkArray,hit2->getX(),y2-i);  
  85.                                 // 如果是已经消除的那么 就可以继续查询  
  86.                                 if (!hitteim->getIsEliminate()){  
  87.                                         LLKAlgorithm::removeAllArray(temparray,false);  
  88.                                         break;  
  89.                                 }else {  
  90.                                         temparray->addObject(hitteim);  
  91.                                 }  
  92.                         }  
  93.                 }  
  94.   
  95.         }  
  96.   
  97.   
  98.   
  99.         return temparray;  
  100. }  

其中返回的 array 就是两个图片的之间的路径  包含两张图片在内。

对于两张图片是否可以垂直相连或者横向相连这个我不用多讲大家都应该明白怎么去做。

下面讲解一个拐角相连的情况
首先我先上张图


      看到这张图片的时候大家先看蓝色矩形框里面 是两张可以经过一个拐角消除的图片  但是怎么确定两张图片可以经过一个拐角就可以连接呢 
   大家有没有发现 这两个张图片刚好是矩形的两个对角顶点 。也就是说围绕着两张图片我们可以画出一个最小的矩形,而矩形的其中两个顶点就是这两张图片。
   好大家如果理解了这里 我们就说下面的,如果不理解好好的想一下。既然已知矩形的 其中两个顶点,那么另外两个顶点的坐标也就轻松的计算出来。就是我们看到的两个绿色的框。
    我们先拿出最上面的那个绿色的矩形框,我们发现他不是一个空白或者说已经消除的一个图片 。那么这个顶点是不符合规则的。我们看下面的那个绿色矩形框。 我们惊奇的发现 他竟然和我们选择的那两张(蓝色框)图片能直接连通 也就是通过这个绿色的矩形框(已经消除掉的) 我们可以把他转化成 一个横向可以连通和一个纵向可以连通的。
    看到这里有的人或许已经恍然大悟了。其实我们要向知道两个点是否可以经过一个拐角相连,我们首先要确定两个图片的坐标点是可以画出一个矩形的并且这个矩形的两个对角顶点就是你选中的两张图片。(必须是对角)然后我们找出这两个矩形另外两个顶点的坐标,找到时候首先要确定找到这个顶点必须是已经消除的掉的一个空白在哪里,或者说没有阻碍物。如果找到一个这样的顶点,那么只要这个顶点能和我们刚开始选择的那两张图片 形成一个纵向的连通和一个横向的连通 那么就说明这两个点可以经过一个拐角进行相连。
  简单一点说就是 两个拐角的==想办法转成===》一个纵向连通+一个横向连通。
  说到这里不知道大家是否已经明白我所表达的意思。
主要代码实现

[cpp]  view plain copy
  1. CCArray*  LLKAlgorithm::oneCorner(cocos2d::CCArray* llkArray,cocos2d::CCArray* hitArray){  
  2.         CustomSprite* hit1=(CustomSprite*)hitArray->objectAtIndex(0);// 取出第一个  
  3.         CustomSprite* hit2=(CustomSprite*)hitArray->objectAtIndex(1);// 取出第二个  
  4.         int x1=hit1->getX();  
  5.         int x2=hit2->getX();  
  6.         int y1=hit1->getY();  
  7.         int y2=hit2->getY();  
  8.         bool isXg=x1>x2?true:false;//如果是true 表示hit1 在hit2 的后面  
  9.         bool isYg=y1>y2?true:false;//如果是true 表示hit1 在hit2 的上面  
  10.         // 下面我们计算出矩形的另外的两个重点  
  11.         // 先计算出  在矩形上面所对应的   
  12.         int temx=0;  
  13.         int temy=0;          
  14.   
  15.         // 求取最上面的哪一个对应的坐标点  
  16.   
  17.         if(isYg){  
  18.                 temy=hit1->getY();  
  19.                 temx=hit2->getX();  
  20.         }else {  
  21.                 temy=hit2->getY();  
  22.                 temx=hit1->getX();  
  23.         }  
  24.         CCArray* temparray=CCArray::create();// 记录两个点之间 所经过的点  
  25.   
  26.         CustomSprite* hity=LLKAlgorithm::getCustByXandY(llkArray,temx,temy);// 得到最上面的那个对应的矩形顶点的 精灵图片  
  27.         CCArray* tempHit=CCArray::create();  
  28.         //顶点必须是已经消除的 要不肯定不能贯通  
  29.         if (hity->getIsEliminate()){  
  30.                 tempHit->addObject(hity);  
  31.                 tempHit->addObject(isYg?hit1:hit2);  
  32.                 CCArray* temx=LLKAlgorithm::horizon(llkArray,tempHit);// 获取X 方向上是否可以连通  
  33.                 if(temx->count()>0){// 表示可以连通  
  34.                         temparray->addObjectsFromArray(temx);  
  35.                         LLKAlgorithm::removeAllArray(tempHit,false);  
  36.                         tempHit->addObject(hity);  
  37.                         tempHit->addObject(isYg?hit2:hit1);  
  38.                         CCArray* temy=LLKAlgorithm::vertical(llkArray,tempHit);  
  39.                         if (temy->count()>0){  
  40.                                 temparray->removeObject(hity,false);  
  41.                                 temparray->addObjectsFromArray(temy);  
  42.                         }else {  
  43.                                 LLKAlgorithm::removeAllArray(temparray,false);  
  44.                         }  
  45.                 }else {  
  46.                         LLKAlgorithm::removeAllArray(tempHit,false);  
  47.                 }  
  48.         }  
  49.         // 表示上面的路走不通  
  50.         if (temparray->count()==0){  
  51.                 // 获取X 方向矩形所对应的的点                  
  52.                 //temx=isXg?hit1->getX():hit2->getX();  
  53.                 //temy=isXg?hit2->getY():hit1->getY();  
  54.   
  55.                 if (isYg){  
  56.                         temy=hit2->getY();  
  57.                         temx=hit1->getX();  
  58.                 }else {  
  59.                         temy=hit1->getY();  
  60.                         temx=hit2->getX();                  
  61.                 }  
  62.   
  63.                 CustomSprite* hitx=LLKAlgorithm::getCustByXandY(llkArray,temx,temy);// 得到最上面的那个对应的矩形顶点的 精灵图片  
  64.                 if (hitx->getIsEliminate()){  
  65.                         tempHit->addObject(hitx);  
  66.                         tempHit->addObject(isYg?hit2:hit1);  
  67.                         CCArray* temx=LLKAlgorithm::horizon(llkArray,tempHit);// 获取X 方向上是否可以连通  
  68.                         if(temx->count()>0){// 表示可以连通  
  69.                                 temparray->addObjectsFromArray(temx);  
  70.                                 LLKAlgorithm::removeAllArray(tempHit,false);  
  71.                                 tempHit->addObject(hitx);  
  72.                                 tempHit->addObject(isYg?hit1:hit2);  
  73.                                 CCArray* temy=LLKAlgorithm::vertical(llkArray,tempHit);  
  74.                                 if (temy->count()>0){  
  75.                                         temparray->removeObject(hitx,false);  
  76.                                         temparray->addObjectsFromArray(temy);  
  77.                                 }else {  
  78.                                         LLKAlgorithm::removeAllArray(temparray,false);  
  79.                                 }  
  80.                         }else {  
  81.                                 LLKAlgorithm::removeAllArray(tempHit,false);  
  82.                         }  
  83.                 }  
  84.   
  85.         }  
  86.   
  87.         return temparray;  
  88.   
  89. }  

下面我们说下拐两角 可以相连的。


大家看看蓝色区域内的是我选择的两张图片。从图中我们看出这两张图片是可以经过两个拐角相连的。
那么如何知道可以经过两个拐角可以 可以相连的 我相信通过上面那一个拐角的算法 大家或许就可以猜出来了。这里我详细说明一下 首先我们拿出一个点  那么就像这个点的上下左右去找,找到一个 可以经过一个拐角和另外一个点相连的。经过一个拐角的算法请看上面那个讲解。首先找到的这个点可以和我们拿出的这个点纵向相连或者横向相连 。(但是必须保证这个点已经没有别的图片占位置或者说是一个空白)。如果能找到这样的一个点那么就可以说明我们开始选择的两个图片是可以经过两个拐角进行相连的。
总体来说 可以这样理解  两个拐角==转化成===》(一个横向相连/纵向相连)+ 一个拐角可以相连的
一个拐角的看上面的解释。
主要实现代码

[cpp]  view plain copy
  1. CCArray*  LLKAlgorithm::twoCorner(cocos2d::CCArray* llkArray,cocos2d::CCArray* hitArray){  
  2.   
  3.         bool isjiance=false// 这个主要来表示是否走了 一个拐角的判断  
  4.         // 先获取 当前X 的最大是多少  y 的最大是多少  
  5.         CustomSprite* lastCutom=(CustomSprite*)llkArray->lastObject();  
  6.         int max=lastCutom->getX();  
  7.         int may=lastCutom->getY();  
  8.         CustomSprite* hit1=(CustomSprite*)hitArray->objectAtIndex(0);// 取出第一个  
  9.         CustomSprite* hit2=(CustomSprite*)hitArray->objectAtIndex(1);// 取出第二个  
  10.   
  11.         // 随便拿出一个点  向他的四个方向出发 看看能否和另外一个变成一个拐角相连  
  12.         // 这里我们就拿出取出的第一个点吧 hit1  
  13.   
  14.         CCArray* temparray=CCArray::create();// 记录两个点之间 所经过的点  
  15.         int x1=hit1->getX(); // 得到第一个X 坐标  
  16.         int y1=hit1->getY(); // 得到第1个Y坐标  
  17.         // 首先向左检测  
  18.         CCArray* temphit=CCArray::create();   
  19.         temphit->addObject(hit2);  
  20.         for(int i=(x1-1);i>=0;i--){  
  21.                 CustomSprite* tepcou =LLKAlgorithm::getCustByXandY(llkArray, i, y1);  
  22.                 if (tepcou->getIsEliminate()){  
  23.                         // 判断看能否组成一个矩形  
  24.                         temparray->addObject(tepcou);  
  25.                         if(tepcou->getX()==hit2->getX()||hit2->getY()==tepcou->getY()){  
  26.   
  27.                                 continue;  
  28.                         }  
  29.                         isjiance=true;  
  30.                         temphit->addObject(tepcou);  
  31.                         CCArray* temparr=LLKAlgorithm::oneCorner(llkArray,temphit);  
  32.                         if (temparr->count()>0){  
  33.                                 temparray->addObjectsFromArray(temparr);  
  34.                                 break;  
  35.                         }else {  
  36.                                 if(i==0){  
  37.                                         LLKAlgorithm::removeAllArray(temparray,false);  
  38.                                 }  
  39.   
  40.                                 temphit->removeLastObject(false);  
  41.                         }  
  42.                 }else{  
  43.                         LLKAlgorithm::removeAllArray(temparray,false);  
  44.   
  45.                         break;  
  46.                 }  
  47.   
  48.         }  
  49.   
  50.         if (isjiance==false){  
  51.                 LLKAlgorithm::removeAllArray(temparray,false);                          
  52.         }  
  53.   
  54.         if(temparray->count()==0){  
  55.                 bool isjiance=false;   
  56.                 // 向右检测  
  57.                 for(int i=(x1+1);i<=max;i++){  
  58.                         CustomSprite* tepcou =LLKAlgorithm::getCustByXandY(llkArray, i, y1);  
  59.                         if (tepcou->getIsEliminate()){  
  60.                                 // 判断看能否组成一个矩形  
  61.                                 temparray->addObject(tepcou);  
  62.                                 if(tepcou->getX()==hit2->getX()||hit2->getY()==tepcou->getY()){  
  63.                                         continue;  
  64.                                 }  
  65.                                 isjiance=true;   
  66.                                 temphit->addObject(tepcou);  
  67.                                 CCArray* temparr=LLKAlgorithm::oneCorner(llkArray,temphit);  
  68.                                 if (temparr->count()>0){  
  69.                                         temparray->addObjectsFromArray(temparr);  
  70.                                         break;  
  71.                                 }else {  
  72.                                         if(i==max){  
  73.                                                 LLKAlgorithm::removeAllArray(temparray,false);  
  74.                                         }                                  
  75.                                         temphit->removeLastObject(false);  
  76.                                 }  
  77.                         }else{  
  78.                                 LLKAlgorithm::removeAllArray(temparray,false);                          
  79.                                 break;  
  80.                         }  
  81.                 }  
  82.   
  83.                 if (isjiance==false){  
  84.                         LLKAlgorithm::removeAllArray(temparray,false);                          
  85.                 }  
  86.         }  
  87.   
  88.         if(temparray->count()==0){  
  89.                 bool isjiance=false;   
  90.                 // 向下检测                  
  91.                 for(int i=(y1-1);i>=0;i--){  
  92.                         CustomSprite* tepcou =LLKAlgorithm::getCustByXandY(llkArray, x1, i);  
  93.                         if (tepcou->getIsEliminate()){  
  94.                                 temparray->addObject(tepcou);  
  95.                                 // 判断看能否组成一个矩形  
  96.                                 if(tepcou->getX()==hit2->getX()||hit2->getY()==tepcou->getY()){                                  
  97.                                         continue;  
  98.                                 }  
  99.                                 isjiance=true;   
  100.                                 temphit->addObject(tepcou);  
  101.                                 CCArray* temparr=LLKAlgorithm::oneCorner(llkArray,temphit);  
  102.                                 if (temparr->count()>0){  
  103.                                         temparray->addObjectsFromArray(temparr);  
  104.                                         break;  
  105.                                 }else {  
  106.                                         if (i==0){  
  107.                                                 LLKAlgorithm::removeAllArray(temparray,false);  
  108.                                         }                                          
  109.                                         temphit->removeLastObject(false);  
  110.                                 }  
  111.                         }else{  
  112.                                 LLKAlgorithm::removeAllArray(temparray,false);  
  113.                                 break;  
  114.                         }  
  115.                 }  
  116.                 if (isjiance==false){  
  117.                         LLKAlgorithm::removeAllArray(temparray,false);                          
  118.                 }  
  119.         }  
  120.   
  121.   
  122.         if(temparray->count()==0){  
  123.                 bool isjiance=false;   
  124.                 // 向上检测                  
  125.                 for(int i=(y1+1);i<=may;i++){  
  126.                         CustomSprite* tepcou =LLKAlgorithm::getCustByXandY(llkArray, x1, i);  
  127.                         if (tepcou->getIsEliminate()){  
  128.                                 temparray->addObject(tepcou);  
  129.                                 // 判断看能否组成一个矩形  
  130.                                 if(tepcou->getX()==hit2->getX()||hit2->getY()==tepcou->getY()){  
  131.                                         continue;  
  132.                                 }  
  133.                                 isjiance=true;   
  134.                                 temphit->addObject(tepcou);  
  135.                                 CCArray* temparr=LLKAlgorithm::oneCorner(llkArray,temphit);  
  136.                                 if (temparr->count()>0){  
  137.                                         temparray->addObjectsFromArray(temparr);          
  138.                                         break;  
  139.                                 }else {  
  140.                                         if(i==may){  
  141.                                                 LLKAlgorithm::removeAllArray(temparray,false);  
  142.                                         }  
  143.   
  144.                                         temphit->removeLastObject(false);  
  145.                                 }  
  146.                         }else{  
  147.                                 LLKAlgorithm::removeAllArray(temparray,false);  
  148.   
  149.                                 break;  
  150.                         }  
  151.                 }  
  152.                 if (isjiance==false){  
  153.                         LLKAlgorithm::removeAllArray(temparray,false);                          
  154.                 }  
  155.         }  
  156.   
  157.         if (temparray->count()>0){  
  158.                 temparray->addObject(hit1);  
  159.         }  
  160.   
  161.         return temparray;  

写到这里连连看的算法基本算是已经完成了
     我在网上看了很多方法感觉不太容易理解,这个是我自己想出来的。感觉很通俗易懂,其实就是化繁为简。我最麻烦的变成最简单。不过连连看的算法有很多种。不如著名的A* 寻路算法就可以。不过我感觉那个给大家讲解其实会很麻烦,有希望了解了解的同学可以在百度上上搜索一下A* 寻路算法。
     其实我子所以写这个练练看看的算法是交大家以后学习中的一种思路,有些同学一开始把问题弄得很复杂导致一时半会想不通,我建议刚开始考虑情况的时候从最简单的开始考虑。到繁琐的阶段的时候看看能不能转化成 简单的方式。中国人其实都喜欢大事化小 小事化了  哈哈。 本章讲解结束。 至于重新布局+自动查找 等算法我会慢慢加进去 希望大家耐心等待。

    另外给大家说下以后我所有的博客首发地址将会是天地会的论坛,由于我是他们哪里的原创管理。所以我以后在发布博客首发地址将会天地会感兴趣的同学可以关注一下

  http://bbs.9ria.com/forum.php?mod=forumdisplay&fid=318



     我给本算法起名字交错化繁为简 算法。

       如果没有看懂的同学可给我留言,我给给大家仔细讲解一下

源码下载

更多 0

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值