/// <summary>
    /// Returns the matches found for a single GameObject
    /// </summary>
    /// <param name="go"></param>
    /// <returns></returns>
    public MatchesInfo GetMatches(GameObject go)
    {
        MatchesInfo matchesInfo = new MatchesInfo();

        var horizontalMatches = GetMatchesHorizontally(go);

        if (ContainsDestroyRowColumnBonus(horizontalMatches))
        {
            horizontalMatches = GetEntireRow(go);
            if (!BonusTypeUtilities.ContainsDestroyWholeRowColumn(matchesInfo.BonusesContained))
            {
                matchesInfo.BonusesContained |= BonusType.DestroyWholeRowColumn;
            }
        }
        matchesInfo.AddObjectRange(horizontalMatches);

        var verticalMatches = GetMatchesVertically(go);

        if (ContainsDestroyRowColumnBonus(verticalMatches))
        {
            verticalMatches = GetEntireColumn(go);
            if (!BonusTypeUtilities.ContainsDestroyWholeRowColumn(matchesInfo.BonusesContained))
            {
                matchesInfo.BonusesContained |= BonusType.DestroyWholeRowColumn;
            }
        }
        matchesInfo.AddObjectRange(verticalMatches);

        return(matchesInfo);
    }
Exemple #2
0
    public MatchesInfo GetMatches(GameObject obj)
    {
        MatchesInfo matchesInfo = new MatchesInfo();

        var horizontalMatches = GetMatchesHorizontally(obj);

        matchesInfo.AddObjectRange(horizontalMatches);

        var verticalMatches = GetMatchesVertically(obj);

        matchesInfo.AddObjectRange(verticalMatches);

        return(matchesInfo);
    }
Exemple #3
0
    } // GetEmptyItemsOnColumn()

    /// <summary>
    /// Get all the matches adjacent to the candy
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public MatchesInfo GetMatches(GameObject obj)
    {
        MatchesInfo matchesInfo = new MatchesInfo();

        // Get any horizontal matches adjacent to the passed object
        var horizontalMatches = GetMatchesHorizontally(obj);

        // Does the match contain a bonus bean that destroys the entire row + column?
        if (ContainsDestroyWholeRowColumnBonus(horizontalMatches))
        {
            // if yes, then get all the objects in the row.
            horizontalMatches = GetEntireRow(obj);

            // if the matches info doesn't have the info about the bonus, make sure it does.
            if (!BonusTypeChecker.ContainsDestroyWholeWorColumn(matchesInfo.BonusesContained))
            {
                matchesInfo.BonusesContained = BonusType.DestroyWholeRowColumn;
            }
        }

        // Add all the row matches to the list
        matchesInfo.AddObjectRange(horizontalMatches);

        // ==== Now do the same for vertical column ====


        // Get any horizontal matches adjacent to the passed object
        var verticalMatches = GetMatchesVertically(obj);

        // Does the match contain a bonus bean that destroys the entire row + column?
        if (ContainsDestroyWholeRowColumnBonus(verticalMatches))
        {
            // if yes, then get all the objects in the column.
            verticalMatches = GetEntireColumn(obj);

            // if the matches info doesn't have the info about the bonus, make sure it does.
            if (!BonusTypeChecker.ContainsDestroyWholeWorColumn(matchesInfo.BonusesContained))
            {
                matchesInfo.BonusesContained = BonusType.DestroyWholeRowColumn;
            }
        }

        // Add all the vertical matches to the list
        matchesInfo.AddObjectRange(verticalMatches);

        // return the list of all matched candies
        return(matchesInfo);
    }
Exemple #4
0
    public MatchesInfo getMatches(GameObject go1, GameObject go2)
    {
        MatchesInfo matchesInfo = new MatchesInfo();
        var         matches     = GetAllMatches(go1, go2);

        matchesInfo.AddObjectRange(matches);
        return(matchesInfo);
    }
Exemple #5
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);
    }
    // Checks for horizontal matches
    public MatchesInfo GetMatches(GameObject go)
    {
        MatchesInfo matchesInfo = new MatchesInfo();

        var horizontalMatches = GetMatchesHorizontally(go);
        if (ContainsDestroyRowColumnBonus(horizontalMatches))
        {
            horizontalMatches = GetEntireRow(go);
            if (!BonusTypeUtilities.ContainsDestroyWholeRowColumn(matchesInfo.BonusesContained))
            {
                matchesInfo.BonusesContained |= BonusType.DestroyWholeRowColumn;
            }
        }
        matchesInfo.AddObjectRange(horizontalMatches);

        var verticalMatches = GetMatchesVertically(go);
        if (ContainsDestroyRowColumnBonus(verticalMatches))
        {
            verticalMatches = GetEntireColumn(go);
            if (!BonusTypeUtilities.ContainsDestroyWholeRowColumn(matchesInfo.BonusesContained))
            {
                matchesInfo.BonusesContained |= BonusType.DestroyWholeRowColumn;
            }
        }
        matchesInfo.AddObjectRange(verticalMatches);

        return matchesInfo;
    }
Exemple #7
0
    /// <summary>
    /// IMPORTANT
    /// Do not delete this overload, as it is used dependently by the other GetMatches overload.
    /// </summary>
    /// <param name="go"></param>
    /// <returns></returns>
    public MatchesInfo GetMatches(GameObject go)
    {
        MatchesInfo matchesInfo = new MatchesInfo();

        var horizontalMatches = GetMatchesHorizontally(go);
        matchesInfo.AddObjectRange(horizontalMatches);

        var verticalMatches = GetMatchesVertically(go);
        matchesInfo.AddObjectRange(verticalMatches);

        return matchesInfo;
    }