示例#1
0
    public MatchesInfo GetAllShapes()
    {
        MatchesInfo matchesInfo = new MatchesInfo();

        foreach (var item in shapes)
        {
            matchesInfo.AddObject(item);
        }

        return(matchesInfo);
    }
示例#2
0
    public MatchesInfo GetMatches(GameObject go, GameObject go2 = null)
    {
        BonusType goBonus  = go.GetComponent <Shape>().Bonus;
        BonusType go2Bonus = BonusType.None;

        if (go2 != null)
        {
            go2Bonus = go2.GetComponent <Shape>().Bonus;
        }

        MatchesInfo matchesInfo = new MatchesInfo
        {
            OriginGameObject = go
        };

        bool[,] bonusUsed = new bool[Constants.Rows, Constants.Columns];
        for (int i = 0; i < Constants.Rows; i++)
        {
            for (int j = 0; j < Constants.Columns; j++)
            {
                bonusUsed[i, j] = false;
            }
        }
        if (goBonus == BonusType.Ultimate)
        {
            if (go2Bonus == BonusType.Ultimate)
            {
                matchesInfo = GetAllShapes();
                matchesInfo.DestroyedByBonus = true;
            }
        }
        else
        {
            if (go2Bonus == BonusType.Ultimate)
            {
                matchesInfo.AddObject(go2);
                foreach (var item in shapes)
                {
                    if (item.GetComponent <Shape>().Type == go.GetComponent <Shape>().Type)
                    {
                        matchesInfo.AddObject(item);
                    }
                }
                matchesInfo.DestroyedByBonus = true;
            }
            else if ((goBonus == BonusType.Bomb) && (go2Bonus == BonusType.Bomb))
            {
                go.GetComponent <Shape>().Bonus  = BonusType.None;
                go2.GetComponent <Shape>().Bonus = BonusType.None;
                matchesInfo.AddObjectRange(GetBombRadius(go, 2));
                matchesInfo.AddObjectRange(GetBombRadius(go2, 2));
                matchesInfo.DestroyedByBonus = true;
            }
            else if (((goBonus == BonusType.Vertical) || (goBonus == BonusType.Horizontal)) &&
                     ((go2Bonus == BonusType.Vertical) || (go2Bonus == BonusType.Horizontal)))
            {
                go.GetComponent <Shape>().Bonus  = BonusType.None;
                go2.GetComponent <Shape>().Bonus = BonusType.None;
                matchesInfo.AddObjectRange(GetEntireColumn(go));
                matchesInfo.AddObjectRange(GetEntireRow(go));
                matchesInfo.DestroyedByBonus = true;
            }
            else if (((goBonus == BonusType.Vertical) || (goBonus == BonusType.Horizontal)) &&
                     (go2Bonus == BonusType.Bomb))
            {
                matchesInfo.AddObjectRange(GetBombAndVerticalOrHorizontal(go, go2));
                matchesInfo.DestroyedByBonus = true;
            }
            else if ((goBonus == BonusType.Bomb) &&
                     ((go2Bonus == BonusType.Vertical) || (go2Bonus == BonusType.Horizontal)))
            {
                matchesInfo.AddObjectRange(GetBombAndVerticalOrHorizontal(go, go2));
                matchesInfo.DestroyedByBonus = true;
            }
            else
            {
                var horizontalMatches = GetMatchesHorizontally(go);
                matchesInfo.AddObjectRange(horizontalMatches);
                matchesInfo.HorizontalMatches = horizontalMatches.Count();

                var verticalMatches = GetMatchesVertically(go);
                matchesInfo.AddObjectRange(verticalMatches);
                matchesInfo.VerticalMatches = verticalMatches.Count();
            }

            bool containsBonuses = false;

            do
            {
                containsBonuses = false;

                List <GameObject> temp = new List <GameObject>(matchesInfo.MatchedCandy);
                foreach (var item in temp)
                {
                    Shape shape = item.GetComponent <Shape>();
                    switch (shape.Bonus)
                    {
                    case BonusType.Horizontal:
                        bonusUsed[shape.Row, shape.Column] = true;
                        shape.Bonus = BonusType.None;
                        matchesInfo.AddObjectRange(GetEntireRow(item));
                        matchesInfo.DestroyedByBonus = true;
                        break;

                    case BonusType.Vertical:
                        bonusUsed[shape.Row, shape.Column] = true;
                        shape.Bonus = BonusType.None;
                        matchesInfo.AddObjectRange(GetEntireColumn(item));
                        matchesInfo.DestroyedByBonus = true;
                        break;

                    case BonusType.Bomb:
                        bonusUsed[shape.Row, shape.Column] = true;
                        shape.Bonus = BonusType.None;
                        matchesInfo.AddObjectRange(GetBombRadius(item, 1));
                        matchesInfo.DestroyedByBonus = true;
                        break;

                    case BonusType.Ultimate:
                        bonusUsed[shape.Row, shape.Column] = true;
                        break;

                    default:
                        break;
                    }
                }

                foreach (var item in matchesInfo.MatchedCandy)
                {
                    Shape shape = item.GetComponent <Shape>();

                    if (bonusUsed[shape.Row, shape.Column] == true)
                    {
                        shape.Bonus = BonusType.None;
                    }

                    if (shape.Bonus != BonusType.None)
                    {
                        containsBonuses = true;
                    }
                }
            } while (containsBonuses == true);
        }

        return(matchesInfo);
    }