예제 #1
0
    public IEnumerator ClearBlock(GameObject block)
    {
        bool isBall   = false;
        bool isRef    = false;
        bool isBlue   = false;
        bool isGreen  = false;
        bool isRed    = false;
        bool isCoin   = false;
        bool isGoalie = false;

        int numBalls   = 0;
        int numRefs    = 0;
        int numBlues   = 0;
        int numGreens  = 0;
        int numReds    = 0;
        int numCoins   = 0;
        int numGoalies = 0;

        IEnumerable <GameObject> totalMatches;
        var sameBlocks = shapes.GetBlockInEntireBoard(block);

        foreach (var item in sameBlocks)
        {
            collectBlockAbilityBlocks++;
            shapes.Remove(item);
            RemoveFromScene(item);
        }

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

        //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(Constants.MoveAnimationMinDuration * maxDistance));

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

        while (totalMatches.Count() >= Constants.MinimumMatches)
        {
            isBall   = false;
            isRef    = false;
            isBlue   = false;
            isGreen  = false;
            isRed    = false;
            isCoin   = false;
            isGoalie = false;

            numBalls   = 0;
            numRefs    = 0;
            numBlues   = 0;
            numGreens  = 0;
            numReds    = 0;
            numCoins   = 0;
            numGoalies = 0;

            soundManager.PlayCrincle();

            foreach (var item in totalMatches)
            {
                if (item.GetComponent <Shape>().Type == "Ball")
                {
                    isBall = true;
                    numBalls++;
                }
                else if (item.GetComponent <Shape>().Type == "Ref")
                {
                    isRef = true;
                    numRefs++;
                }
                else if (item.GetComponent <Shape>().Type == "player_blue")
                {
                    isBlue = true;
                    numBlues++;
                }
                else if (item.GetComponent <Shape>().Type == "player_green")
                {
                    isGreen = true;
                    numGreens++;
                }
                else if (item.GetComponent <Shape>().Type == "player_red")
                {
                    isRed = true;
                    numReds++;
                }
                else if (item.GetComponent <Shape>().Type == "Coin")
                {
                    isCoin = true;
                    numCoins++;
                }
                else if (item.GetComponent <Shape>().Type == "Goalie")
                {
                    isGoalie = true;
                    numGoalies++;
                }

                shapes.Remove(item);
                RemoveFromScene(item);
            }

            if (isBall)
            {
                DealDamage(numBalls);
            }
            if (isRef)
            {
                AddAttribute(0, numRefs, false);
            }
            if (isBlue)
            {
                AddAttribute(1, numBlues, false);
            }
            if (isGreen)
            {
                AddAttribute(2, numGreens, false);
            }
            if (isRed)
            {
                AddAttribute(3, numReds, false);
            }
            if (isCoin)
            {
                AddCoins(numCoins);
            }
            if (isGoalie)
            {
                RegainHp(numGoalies);
            }

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

            //collapse the ones gone
            collapsedCandyInfo = shapes.Collapse(columns);
            //create new ones
            newCandyInfo = CreateNewCandyInSpecificColumns(columns);

            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(Constants.MoveAnimationMinDuration * maxDistance));

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

        StartCheckForPotentialMatches();
    }