Exemple #1
0
 //清除单一颜色
 public void ClearAnyColors(ColorSweet.ColorEnum color)
 {
     print("清除单一颜色");
     for (int x = 0; x < xColumns; x++)
     {
         for (int y = 0; y < yRows; y++)
         {
             if (sweetsarray[y, x].CanColor() && (sweetsarray[y, x].ColorComponent.Color == color || color == ColorSweet.ColorEnum.ANYCOLORS))
             {
                 ClearSweet(x, y);
             }
         }
     }
 }
Exemple #2
0
    public List <GameSweet> MatchSweets(GameSweet sweet, int newX, int newY)
    {
        if (sweet.CanColor())
        {
            ColorSweet.ColorEnum color              = sweet.ColorComponent.Color;
            List <GameSweet>     matchRowSweets     = new List <GameSweet>();
            List <GameSweet>     matchLineSweets    = new List <GameSweet>();
            List <GameSweet>     finishedMatchweets = new List <GameSweet>();

            //----行匹配
            matchRowSweets.Add(sweet);
            for (int i = 0; i <= 1; i++)//0,1代表方向
            {
                for (int xDistance = 1; xDistance < xColumns; xDistance++)
                {
                    int x;
                    if (i == 0)
                    {
                        x = newX - xDistance;
                    }
                    else
                    {
                        x = newX + xDistance;
                    }
                    if (x < 0 || x >= xColumns)
                    {
                        break;
                    }
                    if (sweetsarray[newY, x].CanColor() &&
                        sweetsarray[newY, x].ColorComponent.Color == color)
                    {
                        matchRowSweets.Add(sweetsarray[newY, x]);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (matchRowSweets.Count >= 3)
            {
                for (int i = 0; i < matchRowSweets.Count; i++)
                {
                    finishedMatchweets.Add(matchRowSweets[i]);
                }
                for (int i = 0; i < matchRowSweets.Count; i++)
                {
                    for (int j = 0; j <= 1; j++)//方向
                    {
                        for (int yDisTance = 1; yDisTance < yRows; yDisTance++)
                        {
                            int y;
                            if (j == 0)
                            {
                                y = newY - yDisTance;
                            }
                            else
                            {
                                y = newY + yDisTance;
                            }
                            if (y < 0 || y >= yRows)
                            {
                                break;
                            }
                            if (sweetsarray[y, matchRowSweets[i].X].CanColor() &&
                                sweetsarray[y, matchRowSweets[i].X].ColorComponent.Color == color)
                            {
                                matchLineSweets.Add(sweetsarray[y, matchRowSweets[i].X]);
                            }
                            else
                            {
                                break;//找到第一个不同颜色时直接跳出
                            }
                        }
                    }
                    if (matchLineSweets.Count < 2)//该列表未包含基准颜色块
                    {
                        matchLineSweets.Clear();
                    }
                    else
                    {
                        for (int j = 0; j < matchLineSweets.Count; j++)
                        {
                            finishedMatchweets.Add(matchLineSweets[j]);
                        }
                        break;
                    }
                    //finishedMatchweets.Add(matchRowSweets[i]);
                }
            }
            if (finishedMatchweets.Count >= 3)
            {
                print("匹配"); return(finishedMatchweets);
            }


            matchRowSweets.Clear();
            matchLineSweets.Clear();

            matchLineSweets.Add(sweet);
            for (int i = 0; i <= 1; i++)//0,1代表方向
            {
                for (int yDistance = 1; yDistance < yRows; yDistance++)
                {
                    int y;
                    if (i == 0)
                    {
                        y = newY - yDistance;
                    }
                    else
                    {
                        y = newY + yDistance;
                    }
                    if (y < 0 || y >= yRows)
                    {
                        break;
                    }
                    if (sweetsarray[y, newX].CanColor() &&
                        sweetsarray[y, newX].ColorComponent.Color == color)
                    {
                        matchLineSweets.Add(sweetsarray[y, newX]);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (matchLineSweets.Count >= 3)
            {
                for (int i = 0; i < matchLineSweets.Count; i++)
                {
                    finishedMatchweets.Add(matchLineSweets[i]);
                }


                for (int i = 0; i < matchLineSweets.Count; i++)
                {
                    for (int j = 0; j <= 1; j++)//方向
                    {
                        for (int xDisTance = 1; xDisTance < xColumns; xDisTance++)
                        {
                            int x;
                            if (j == 0)
                            {
                                x = newX - xDisTance;
                            }
                            else
                            {
                                x = newX + xDisTance;
                            }
                            if (x < 0 || x >= xColumns)
                            {
                                break;
                            }
                            if (sweetsarray[matchLineSweets[i].Y, x].CanColor() &&
                                sweetsarray[matchLineSweets[i].Y, x].ColorComponent.Color == color)
                            {
                                matchRowSweets.Add(sweetsarray[matchLineSweets[i].Y, x]);
                            }
                            else
                            {
                                break;//找到第一个不同颜色时直接跳出
                            }
                        }
                    }
                    if (matchRowSweets.Count < 2)//该列表未包含基准颜色块
                    {
                        matchRowSweets.Clear();
                    }
                    else
                    {
                        for (int j = 0; j < matchRowSweets.Count; j++)
                        {
                            finishedMatchweets.Add(matchRowSweets[j]);
                        }
                        break;
                    }
                    //finishedMatchweets.Add(matchLineSweets[i]);
                }
            }
            if (finishedMatchweets.Count >= 3)
            {
                print("匹配"); return(finishedMatchweets);
            }
        }

        print("匹配失败");
        return(null);
    }