04L型匹配和T型匹配的核心算法

发布时间:2025-12-09 17:47:26 浏览次数:3


//自己写的不完全

public List<GameSweet> MatchSweets(GameSweet sweet,int newX,int newY){if (sweet.CanColor()){ColorSweet.ColorType color=sweet.ColoredComponent.Color;List<GameSweet> matchRowSweets=new List<GameSweet>(); //行List<GameSweet> matchLineSweets=new List<GameSweet>(); //竖List<GameSweet> finishedMatchingSweets=new List<GameSweet>(); //完成后的所有匹配//行匹配matchRowSweets.Add(sweet);//i为0 的时候 往左遍历 为1的时候往右边遍历for (int i = 0; i <=1; i++){//往左依次递减 //往右依次递加 xDistance偏移量for (int xDistance= 1; xDistance < xColumn; xDistance++){int x; //偏移之后要判断的位置if (i==0) //左减{x = newX - xDistance; }else //右加{x = newX + xDistance;}//排除边界值if (x<0||x>=xColumn){break;}//判断满足条件if (sweets[x,newY].CanColor()&& sweets[x, newY].ColoredComponent.Color==color){matchRowSweets.Add(sweets[x,newY]);}else{break;}}}//行匹配完毕if (matchRowSweets.Count>=3){//进行L形匹配for (int i = 0; i < matchRowSweets.Count; i++){finishedMatchingSweets.Add(matchRowSweets[i]);}}if (finishedMatchingSweets.Count>=3){return finishedMatchingSweets;}//列匹配matchLineSweets.Add(sweet);//i为0 的时候 往左遍历 为1的时候往右边遍历for (int i = 0; i <= 1; i++){//往左依次递减 //往右依次递加 xDistance偏移量for (int yDistance = 1; yDistance < yRow;yDistance++){int y; //偏移之后要判断的位置if (i == 0) //左减{y = newY - yDistance;}else //右加{y = newY + yDistance;}//排除边界值if (y < 0 || y >= yRow){break;}//判断满足条件if (sweets[newX, y].CanColor() && sweets[newX, y].ColoredComponent.Color == color){matchLineSweets.Add(sweets[newX, y]);}else{break;}}}//行匹配完毕if (matchLineSweets.Count >= 3){for (int i = 0; i < matchLineSweets.Count; i++){finishedMatchingSweets.Add(matchLineSweets[i]);}}if (finishedMatchingSweets.Count >= 3){return finishedMatchingSweets;}}return null;}

//

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477