Beispiel #1
0
    public MatchesInfo GetMatches(GameObject go)
    {
        MatchesInfo matchesInfo = new MatchesInfo();

        var horizontalMatches = GetMatchesHorizontally(go);

        if (ContainsDestroyWholeRowColumnBonus(horizontalMatches))
        {
            horizontalMatches = GetEntireRow(go);

            if (!BonusTypeChecker.ContainsDestroyWholeRowColumn(matchesInfo.BonusesContained))
            {
                matchesInfo.BonusesContained = BonusType.DestroyWholeRowColumn;
            }
        }
        matchesInfo.AddObjectRange(horizontalMatches);

        var verticalMatches = GetMatchesVertically(go);

        if (ContainsDestroyWholeRowColumnBonus(verticalMatches))
        {
            verticalMatches = GetEntireColumn(go);

            if (!BonusTypeChecker.ContainsDestroyWholeRowColumn(matchesInfo.BonusesContained))
            {
                matchesInfo.BonusesContained = BonusType.DestroyWholeRowColumn;
            }
        }
        matchesInfo.AddObjectRange(verticalMatches);

        return(matchesInfo);
    }
Beispiel #2
0
 private bool ContainsDestroyWholeRowColumnBonus(IEnumerable <GameObject> matches)
 {
     if (matches.Count() >= GameVariables.MinimumMatches)
     {
         foreach (var item in matches)
         {
             if (BonusTypeChecker.ContainsDestroyWholeRowColumn(item.GetComponent <Candy> ().Bonus))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #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);
    }
Beispiel #4
0
    } // GetMatchesVertically()

    private bool ContainsDestroyWholeRowColumnBonus(IEnumerable <GameObject> matches)
    {
        // did enough matches exist
        if (matches.Count() >= GameVariables.MinimumMatches)
        {
            // Does the list of matches contain a bonus candy that destroys the row and column?
            foreach (var item in matches)
            {
                if (BonusTypeChecker.ContainsDestroyWholeWorColumn(item.GetComponent <Candy>().Bonus))
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Beispiel #5
0
    private IEnumerator FindMatchesAndCollapse(Collider2D hit2)
    {
        var hitGo2 = hit2.GetComponent <Collider2D>().gameObject;

        marbles.Swap(hitGo, hitGo2);

        hitGo.transform.positionTo(GameVariables.AnimationDuration, hit2.transform.position);
        hitGo2.transform.positionTo(GameVariables.AnimationDuration, hitGo.transform.position);
        yield return(new WaitForSeconds(GameVariables.AnimationDuration));

        var hitGoMatchesInfo  = marbles.GetMatches(hitGo);
        var hitGo2MatchesInfo = marbles.GetMatches(hitGo2);

        var totalMatches = hitGoMatchesInfo.MatchedMarbles.Union(hitGo2MatchesInfo.MatchedMarbles).Distinct();


        if (totalMatches.Count() < GameVariables.MinimumMatches)
        {
            //failSwapSFX.Play ();
            hitGo.transform.positionTo(GameVariables.AnimationDuration, hitGo2.transform.position);
            hitGo2.transform.localPositionTo(GameVariables.AnimationDuration, hitGo.transform.position);
            yield return(new WaitForSeconds(GameVariables.AnimationDuration));


            marbles.UndoSwap();

            gm.IncrementScore(Serialization.boardConfig.GENERAL_MatchValue);
            gm.DecrementGoalPanelPoints(Serialization.boardConfig.GENERAL_MatchValue);
            gm.MoveMana();
            gm.MoveProgressIndicator();
            gm.CheckForWin();
        }

        bool addBonus = totalMatches.Count() >= GameVariables.MinimumMatchesForBonus &&
                        !BonusTypeChecker.ContainsDestroyWholeColumn(hitGoMatchesInfo.BonusesContained) &&
                        !BonusTypeChecker.ContainsDestroyWholeColumn(hitGo2MatchesInfo.BonusesContained);

        Marble hitGoCache = null;

        if (addBonus)
        {
            hitGoCache = new Marble();

            var sameTypeGo = hitGoMatchesInfo.MatchedMarbles.Count() > 0 ? hitGo : hitGo2;
            var marble     = sameTypeGo.GetComponent <Marble> ();

            hitGoCache.Initialize(marble.Type, marble.Row, marble.Column);
        }

        int timesRun = 1;

        while (totalMatches.Count() >= GameVariables.MinimumMatches)
        {
            IncreaseScore(totalMatches.Count() - 2 * GameVariables.MatchScore);

            if (timesRun >= 2)
            {
                IncreaseScore(GameVariables.SubsequelMatchScore);
            }

            //successSwapSFX.Play ();


            gm.IncrementScore(Serialization.boardConfig.GENERAL_MatchValue);
            gm.DecrementGoalPanelPoints(Serialization.boardConfig.GENERAL_MatchValue);
            gm.MoveMana();
            gm.MoveProgressIndicator();
            gm.CheckForWin();

            foreach (var item in totalMatches)
            {
                marbles.Remove(item);
                RemoveFromScene(item);
            }

            if (addBonus)
            {
                CreateBonus(hitGoCache);
            }

            addBonus = false;

            var columns = totalMatches.Select(go => go.GetComponent <Marble>().Column).Distinct();

            var collapsedMarbleInfo = marbles.Collapse(columns);

            var newMarbleInfo = CreateNewMarbleInSpecificColumns(columns);

            int maxDistance = Mathf.Max(collapsedMarbleInfo.maxDistance, newMarbleInfo.maxDistance);

            MoveAndAnimate(newMarbleInfo.AlteredMarble, maxDistance);
            MoveAndAnimate(collapsedMarbleInfo.AlteredMarble, maxDistance);

            yield return(new WaitForSeconds(GameVariables.MoveAnimationDuration * maxDistance));

            totalMatches = marbles.GetMatches(collapsedMarbleInfo.AlteredMarble)
                           .Union(marbles.GetMatches(newMarbleInfo.AlteredMarble)).Distinct();

            timesRun++;
        }

        state = GameState.None;
        StartCheckForPotentialMatches();
    }
    private IEnumerator FindMatchesAndCollapse(RaycastHit2D hit2)
    {
        // assign 2nd game object to the one that was touched.
        var hitGo2 = hit2.collider.gameObject;

        // Swap the candy positions
        candies.Swap(hitGo, hitGo2);

        // Move passed item into position 2
        hitGo.transform.positionTo(GameVariables.AnimationDuration, hit2.transform.position);

        // Move item 2 into position
        hitGo2.transform.positionTo(GameVariables.AnimationDuration, hitGo.transform.position);

        // wait until its over.
        yield return(new WaitForSeconds(GameVariables.AnimationDuration));


        var hitGoMatchesInfo = candies.GetMatches(hitGo);

        var hitGo2MatchesInfo = candies.GetMatches(hitGo2);

        // join the first and second lists, de-duplicating, to result in the total matches
        var totalMatches = hitGoMatchesInfo.MatchedCandy.Union(hitGo2MatchesInfo.MatchedCandy).Distinct();


        // if there is not a valid match, such as only being 2 in a row, wrong colors, etc... we need to undo the animated swap.
        if (totalMatches.Count() < GameVariables.MinimumMatches)
        {
            // Move passed item back to position 1
            hitGo.transform.positionTo(GameVariables.AnimationDuration, hitGo2.transform.position);

            // Move item 2 back to its position
            hitGo2.transform.localPositionTo(GameVariables.AnimationDuration, hitGo.transform.position);

            yield return(new WaitForSeconds(GameVariables.AnimationDuration));

            candies.UndoSwap();
        }


        // figure out if we're going to grant a bonus
        bool addBonus = totalMatches.Count() >= GameVariables.MinimumMatchesForBonus &&
                        !BonusTypeChecker.ContainsDestroyWholeWorColumn(hitGoMatchesInfo.BonusesContained) && // if the items being destroyed doesn't already contain a bonus
                        !BonusTypeChecker.ContainsDestroyWholeWorColumn(hitGo2MatchesInfo.BonusesContained);  // if the items being destroyed doesn't already contain a bonus


        Candy hitGoCache = null;

        if (addBonus == true)
        {
            hitGoCache = new Candy();

            // assign one of the two game objects depending if its the same type
            var sameTypeGo = hitGoMatchesInfo.MatchedCandy.Count() > 0 ? hitGo : hitGo2;

            // get a reference to the Candy component on the SameTypeGo gameobject
            var candy = sameTypeGo.GetComponent <Candy>();

            // initialize the bonus candy
            hitGoCache.Initialize(candy.Type, candy.Row, candy.Column);
        }

        // track the while loop
        int timesRun = 1;

        while (totalMatches.Count() >= GameVariables.MinimumMatches)
        {
            // earn points for each 3-item match
            IncreaseScore(totalMatches.Count() - 2 * GameVariables.Match3Score);

            // bonus if multiples
            if (timesRun >= 2)
            {
                IncreaseScore(GameVariables.SubsequelMatchScore);
            }

            // trigger sound effect
            soundManager.PlaySound();

            // Now remove the individual items
            foreach (var item in totalMatches)
            {
                candies.Remove(item);
                RemoveFromScene(item);
            }

            // If there is a bonus candy to be generated, create it.
            if (addBonus)
            {
                CreateBonus(hitGoCache);
            }

            addBonus = false;


            var columns = totalMatches.Select(go => go.GetComponent <Candy>().Column).Distinct();

            var collapsedCandyInfo = candies.Collapse(columns);

            var newCandyInfo = CreateNewCandyInSpecificColumns(columns);

            int maxDistance = Mathf.Max(collapsedCandyInfo.maxDistance, newCandyInfo.maxDistance);

            MoveAndAnimate(newCandyInfo.AlteredCandy, maxDistance);
            MoveAndAnimate(collapsedCandyInfo.AlteredCandy, maxDistance);

            // wait for time for each movement animation that has to occur
            yield return(new WaitForSeconds(GameVariables.MoveAnimationDuration * maxDistance));

            // Checking for new matches in the collapsed columns
            totalMatches = candies.GetRefillMatches(collapsedCandyInfo.AlteredCandy).Union(candies.GetRefillMatches(newCandyInfo.AlteredCandy)).Distinct();

            timesRun++;
        } // end while

        // reset game state
        state = GameState.None;

        // start checking for potential matches again.
        StartCheckForPotentialMatches();
    }
Beispiel #7
0
    private IEnumerator FindMatchesAndCollapse(RaycastHit2D hit2)
    {
        var hitGo2 = hit2.collider.gameObject;

        candies.Swap(hitGo, hitGo2);

        hitGo.transform.positionTo(GameVariables.AnimationDuration, hit2.transform.position);
        hitGo2.transform.positionTo(GameVariables.AnimationDuration, hitGo.transform.position);
        yield return(new WaitForSeconds(GameVariables.AnimationDuration));

        var hitGoMatchesInfo  = candies.GetMatches(hitGo);
        var hitGo2MatchesInfo = candies.GetMatches(hitGo2);

        var totalMatches = hitGoMatchesInfo.MatchedCandy.Union(hitGo2MatchesInfo.MatchedCandy).Distinct();

        if (totalMatches.Count() < GameVariables.MinimumMatches)
        {
            hitGo.transform.positionTo(GameVariables.AnimationDuration, hitGo2.transform.position);
            hitGo2.transform.localPositionTo(GameVariables.AnimationDuration, hitGo.transform.position);
            yield return(new WaitForSeconds(GameVariables.AnimationDuration));

            candies.UndoSwap();
        }
        bool addBonus = totalMatches.Count() >= GameVariables.MinimumMatchesForBonus &&
                        !BonusTypeChecker.ContainsDestroyWholeRowColumn(hitGoMatchesInfo.BonusesContained) &&
                        !BonusTypeChecker.ContainsDestroyWholeRowColumn(hitGo2MatchesInfo.BonusesContained);

        Candy hitGoCache = null;

        if (addBonus)
        {
            hitGoCache = new Candy();

            var sameTypeGo = hitGoMatchesInfo.MatchedCandy.Count() > 0 ? hitGo : hitGo2;
            var candy      = sameTypeGo.GetComponent <Candy> ();

            hitGoCache.Initialize(candy.Type, candy.Row, candy.Column);
        }
        int timesRun = 1;

        while (totalMatches.Count() >= GameVariables.MinimumMatches)
        {
            IncreaseScore(Mathf.Abs(totalMatches.Count() - 2 * GameVariables.Match3Score));

            if (timesRun >= 2)
            {
                IncreaseScore(GameVariables.SubsequelMatchScore);
            }

            soundManager.PlaySound();

            foreach (var item in totalMatches)
            {
                candies.Remove(item);
                RemoveFromScene(item);
            }

            if (addBonus)
            {
                CreateBonus(hitGoCache);
            }
            addBonus = false;

            var columns           = totalMatches.Select(go => go.GetComponent <Candy> ().Column).Distinct();
            var collapseCandyInfo = candies.Collapse(columns);
            var newCandyInfo      = CreateNewCandyInSpecificColumns(columns);
            int maxDistance       = Mathf.Max(collapseCandyInfo.maxDistance, newCandyInfo.maxDistance);

            MoveAndAnimate(newCandyInfo.AlteredCandy, maxDistance);
            MoveAndAnimate(collapseCandyInfo.AlteredCandy, maxDistance);

            yield return(new WaitForSeconds(GameVariables.AnimationDuration * maxDistance));

            totalMatches = candies.GetMatches(collapseCandyInfo.AlteredCandy)
                           .Union(candies.GetMatches(newCandyInfo.AlteredCandy)).Distinct();

            timesRun++;
        }
        state = GameState.None;
        StartCheckForPotentialMatches();
    }