コード例 #1
0
    private bool ContainsDestroyBothRowColumnBonus(IEnumerable <GameObject> horizontalmatches, IEnumerable <GameObject> verticalmatches)
    {
        if (horizontalmatches.Count() >= ConstantsVariable_4.MinimumMatches)
        {
            foreach (var go in horizontalmatches)
            {
                if (BonusTypeUtilities_4.ContainsDestroyBothWholeRowColumn
                        (go.GetComponent <Shape_4>().Bigbonus))
                {
                    return(true);
                }
            }
        }
        if (verticalmatches.Count() >= ConstantsVariable_4.MinimumMatches)
        {
            foreach (var go in verticalmatches)
            {
                if (BonusTypeUtilities_4.ContainsDestroyBothWholeRowColumn
                        (go.GetComponent <Shape_4>().Bigbonus))
                {
                    return(true);
                }
            }
        }



        return(false);
    }
コード例 #2
0
    private bool ContainsDestroyRowColumnBonus(IEnumerable <GameObject> matches)
    {
        if (matches.Count() >= ConstantsVariable_4.MinimumMatches)
        {
            foreach (var go in matches)
            {
                if (BonusTypeUtilities_4.ContainsDestroyWholeRowColumn
                        (go.GetComponent <Shape_4>().Bonus))
                {
                    return(true);
                }
            }
        }

        return(false);
    }
コード例 #3
0
    /// Returns the matches found for a single GameObject
    public MatchesSet_4 GetMatches(GameObject go)
    {
        MatchesSet_4 MatchesSet = new MatchesSet_4();

        var horizontalMatches = GetMatchesHorizontally(go);

        if (ContainsDestroyRowColumnBonus(horizontalMatches))
        {
            horizontalMatches = GetEntireRow(go);
            if (!BonusTypeUtilities_4.ContainsDestroyWholeRowColumn(MatchesSet.BonusesContained))
            {
                MatchesSet.BonusesContained |= BonusType_4.DestroyWholeRowColumn;
            }
        }
        MatchesSet.AddObjectRange(horizontalMatches);

        var verticalMatches = GetMatchesVertically(go);

        if (ContainsDestroyRowColumnBonus(verticalMatches))
        {
            verticalMatches = GetEntireColumn(go);
            if (!BonusTypeUtilities_4.ContainsDestroyWholeRowColumn(MatchesSet.BonusesContained))
            {
                MatchesSet.BonusesContained |= BonusType_4.DestroyWholeRowColumn;
            }
        }
        MatchesSet.AddObjectRange(verticalMatches);

        if (ContainsDestroyBothRowColumnBonus(horizontalMatches, verticalMatches))
        {
            horizontalMatches = GetEntireRow(go);
            verticalMatches   = GetEntireColumn(go);
            if (!BonusTypeUtilities_4.ContainsDestroyBothWholeRowColumn(MatchesSet.BonusesContained))
            {
                MatchesSet.BonusesContained |= BonusType_4.DestroyBothWholeRowColumn;
            }
        }
        MatchesSet.AddObjectRange(horizontalMatches);
        MatchesSet.AddObjectRange(verticalMatches);


        return(MatchesSet);
    }
コード例 #4
0
    private IEnumerator FindMatchesAndCollapse(RaycastHit2D hit2)
    {
        //get the second item that was part of the swipe
        var hitGo2 = hit2.collider.gameObject;

        shapes.Swap(hitGo, hitGo2);

        //move the swapped ones
        hitGo.transform.positionTo(ConstantsVariable_4.AnimationDuration, hitGo2.transform.position);
        hitGo2.transform.positionTo(ConstantsVariable_4.AnimationDuration, hitGo.transform.position);
        yield return(new WaitForSeconds(ConstantsVariable_4.AnimationDuration));

        //get the matches via the helper methods
        var hitGoMatchesSet  = shapes.GetMatches(hitGo);
        var hitGo2MatchesSet = shapes.GetMatches(hitGo2);

        var totalMatches = hitGoMatchesSet.MatchedCandy
                           .Union(hitGo2MatchesSet.MatchedCandy).Distinct();

        //if user's swap didn't create at least a 3-match, undo their swap
        if (totalMatches.Count() < ConstantsVariable_4.MinimumMatches)
        {
            Audio_Source.PlayOneShot(Sounds[0]);
            hitGo.transform.positionTo(ConstantsVariable_4.AnimationDuration, hitGo2.transform.position);
            hitGo2.transform.positionTo(ConstantsVariable_4.AnimationDuration, hitGo.transform.position);
            yield return(new WaitForSeconds(ConstantsVariable_4.AnimationDuration));

            shapes.UndoSwap();
        }
        else
        {
            Audio_Source.PlayOneShot(Sounds[1]);
        }
        if (totalMatches.Count() > ConstantsVariable_4.MinimumMatches)
        {
            Audio_Source.PlayOneShot(Sounds[4]);
        }

        //if more than 3 matches and no Bonus is contained in the line, we will award a new Bonus
        bool addBonus = totalMatches.Count() == ConstantsVariable_4.MinimumMatchesForBonus &&
                        !BonusTypeUtilities_4.ContainsDestroyWholeRowColumn(hitGoMatchesSet.BonusesContained) &&
                        !BonusTypeUtilities_4.ContainsDestroyWholeRowColumn(hitGo2MatchesSet.BonusesContained);

        bool addbigbonus = totalMatches.Count() >= ConstantsVariable_4.MinimumMatchesForBigBonus &&
                           !BonusTypeUtilities_4.ContainsDestroyWholeRowColumn(hitGoMatchesSet.BonusesContained) &&
                           !BonusTypeUtilities_4.ContainsDestroyWholeRowColumn(hitGo2MatchesSet.BonusesContained) &&
                           !BonusTypeUtilities_4.ContainsDestroyBothWholeRowColumn(hitGoMatchesSet.BonusesContained) &&
                           !BonusTypeUtilities_4.ContainsDestroyBothWholeRowColumn(hitGo2MatchesSet.BonusesContained);


        Shape_4 hitGoCache = null;

        if (addBonus)
        {
            //get the game object that was of the same type
            var sameTypeGo = hitGoMatchesSet.MatchedCandy.Count() > 0 ? hitGo : hitGo2;
            hitGoCache = sameTypeGo.GetComponent <Shape_4>();
        }

        if (addbigbonus)
        {
            var allTypeGo = hitGoMatchesSet.MatchedCandy.Count() > 0?hitGo : hitGo2;
            hitGoCache = allTypeGo.GetComponent <Shape_4>();
        }



        int timesRun = 1;

        while (totalMatches.Count() >= ConstantsVariable_4.MinimumMatches)
        {
            //increase score

            IncreaseScore((totalMatches.Count() - 2) * ConstantsVariable_4.Match3Score);

            if (timesRun >= 2)
            {
                IncreaseScore(ConstantsVariable_4.SubsequentMatchScore);
            }


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

            //check and instantiate Bonus if needed
            if (addBonus)
            {
                CreateBonus(hitGoCache);
            }
            if (addbigbonus)
            {
                Debug.Log("Bigbonus");
                CreateBigBonus(hitGoCache);
            }
            addbigbonus = false;
            addBonus    = false;

            //get the columns that we had a collapse
            var columns = totalMatches.Select(go => go.GetComponent <Shape_4>().Column).Distinct();

            //the order the 2 methods below get called is important!!!
            //collapse the ones gone
            var collapsedCandyInfo = shapes.Collapse(columns);
            //create new ones
            var newCandyInfo = CreateNewCandyInSpecificColumns(columns);

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

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



            //will wait for both of the above animations
            yield return(new WaitForSeconds(ConstantsVariable_4.MoveAnimationMinDuration * maxDistance));

            //search if there are matches with the new/collapsed items
            totalMatches = shapes.GetMatches(collapsedCandyInfo.AlteredCandy).
                           Union(shapes.GetMatches(newCandyInfo.AlteredCandy)).Distinct();



            timesRun++;
        }

        state = GameState_4.None;
        StartCheckForPotentialMatches();
    }