示例#1
0
    //This function
    //Breaks all matched shapes
    //And triggers gravity
    public IEnumerator BreakMatchesAndGravity(IEnumerable <GameObject> totalMatches)
    {
        int sequence = 1;

        while (totalMatches.Count() >= Constants.MinimumMatches)
        {
            if (sequence > 2 && turn == "Player")
            {
                player.GetComponent <EquipmentManager> ().AddModifiersOfType("combo");
            }

            int[] matches = new int[CandyPrefabs.Length];
            for (int i = 0; i < matches.Length; i++)
            {
                matches [i] = 0;
            }
            foreach (GameObject match in totalMatches)
            {
                matches [System.Array.IndexOf(GemTypes, match.GetComponent <Shape>().Type)]++;
            }
            for (int i = 0; i < CandyPrefabs.Length; i++)
            {
                if (turn == "Player")
                {
                    player.GetComponent <PlayerScript>().DealDamage(matches [i], i, enemy, sequence);
                }
                else
                {
                    enemy.GetComponent <PlayerScript>().DealDamage(matches [i], i, player, sequence);
                }
            }
            foreach (var item in totalMatches)
            {
                shapes.Remove(item);
                RemoveFromScene(item);
            }
            var columns = totalMatches.Select(go => go.GetComponent <Shape>().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);


            yield return(new WaitForSeconds(Constants.MoveAnimationMinDuration * maxDistance));

            totalMatches = shapes.GetMatches(collapsedCandyInfo.AlteredCandy).
                           Union(shapes.GetMatches(newCandyInfo.AlteredCandy)).Distinct();

            sequence++;
        }
    }
示例#2
0
    private IEnumerator FindMatchesAndCollapse(GameObject hitGo2)
    {
        bool matchPerformed = false;

        shapes.Swap(hitGo, hitGo2);

        // move the swapped ones
        hitGo.transform.DOMove(hitGo2.transform.position, Constants.SwapAnimationDuration);
        hitGo2.transform.DOMove(hitGo.transform.position, Constants.SwapAnimationDuration);
        yield return(new WaitForSeconds(Constants.SwapAnimationDuration));

        BonusType hitGoBonus  = hitGo.GetComponent <Shape>().Bonus;
        BonusType hitGo2Bonus = hitGo2.GetComponent <Shape>().Bonus;

        // check if one of the two objects was combined with an ultimate
        if ((hitGo2Bonus == BonusType.Ultimate) && (hitGoBonus != BonusType.Ultimate) && (hitGoBonus != BonusType.None))
        {
            DuplicateCandy(hitGo);
        }

        if ((hitGoBonus == BonusType.Ultimate) && (hitGo2Bonus != BonusType.Ultimate) && (hitGo2Bonus != BonusType.None))
        {
            DuplicateCandy(hitGo2);
        }

        List <MatchesInfo> matchesInfos = new List <MatchesInfo>();

        // get the matches via the helper methods
        matchesInfos.Add(shapes.GetMatches(hitGo, hitGo2));
        matchesInfos.Add(shapes.GetMatches(hitGo2, hitGo));

        var totalMatches = matchesInfos[0].MatchedCandy.Union(matchesInfos[1].MatchedCandy).Distinct();

        // if user's swap didn't create at least a 3-match, undo their swap
        if (totalMatches.Count() < Constants.MinimumMatches)
        {
            hitGo.transform.DOMove(hitGo2.transform.position, Constants.SwapAnimationDuration);
            hitGo2.transform.DOMove(hitGo.transform.position, Constants.SwapAnimationDuration);
            yield return(new WaitForSeconds(Constants.SwapAnimationDuration));

            shapes.UndoSwap();
        }
        else
        {
            // user performed a match, no need to show the hints anymore
            matchPerformed = true;
            StopCheckForPotentialMatches();
        }

        // decide if a bonus shall be added to one of the 2 user matches
        foreach (var item in matchesInfos)
        {
            if (item.Matches >= Constants.MinimumMatchesForBonus)
            {
                item.CreateBonus = true;
            }
        }

        int timesRun = 0;

        while (totalMatches.Count() >= Constants.MinimumMatches)
        {
            // boolean array to not create score for the same match more than onces
            bool[,] matchScoreCounted = new bool[Constants.Rows, Constants.Columns];
            for (int i = 0; i < Constants.Rows; i++)
            {
                for (int j = 0; j < Constants.Columns; j++)
                {
                    matchScoreCounted[i, j] = false;
                }
            }

            // increase score
            foreach (var item in matchesInfos)
            {
                if (item.DestroyedByBonus == true)
                {
                    bool countScore = true;
                    foreach (var go in item.MatchedCandy)
                    {
                        if (matchScoreCounted[go.GetComponent <Shape>().Row, go.GetComponent <Shape>().Column] == true)
                        {
                            countScore = false;
                        }
                    }
                    if (countScore == true)
                    {
                        foreach (var go in item.MatchedCandy)
                        {
                            matchScoreCounted[go.GetComponent <Shape>().Row, go.GetComponent <Shape>().Column] = true;
                            Vector3 position = Camera.main.WorldToScreenPoint(go.transform.position);
                            IncreaseScoreAndCreatePopUp(Constants.BonusMatchScore, position);
                        }
                    }
                }
                else if (item.Matches == 3)
                {
                    CheckForScoreAndIncrease(item, ref matchScoreCounted, Constants.Match3Score, timesRun);
                }
                else if (item.Matches == 4)
                {
                    CheckForScoreAndIncrease(item, ref matchScoreCounted, Constants.Match4Score, timesRun);
                }
                else if (item.Matches >= 5)
                {
                    CheckForScoreAndIncrease(item, ref matchScoreCounted, Constants.Match5Score, timesRun);
                }
            }

            soundManager.PlayCrinkle();

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

            // check if there are any bonus objects to create
            foreach (var item in matchesInfos)
            {
                if (item.CreateBonus == true)
                {
                    CreateBonus(item.OriginGameObject, item);
                    item.CreateBonus = false;
                }
            }

            // get the columns that we had a collapse
            var columns = totalMatches.Select(go => go.GetComponent <Shape>().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);

            // wait until explosion animation has finished
            yield return(new WaitForSeconds(Constants.ExplosionDuration));

            yield return(new WaitForSeconds(Constants.DelayAfterExplosion));

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

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

            // search if there are matches with the collapsed objects and then new objects
            matchesInfos = new List <MatchesInfo>();
            matchesInfos.AddRange(shapes.GetMatchesInfos(collapsedCandyInfo.AlteredCandy));
            matchesInfos.AddRange(shapes.GetMatchesInfos(newCandyInfo.AlteredCandy));

            // boolean array to not create boni for the same match more than onces
            bool[,] bonusCreated = new bool[Constants.Rows, Constants.Columns];
            for (int i = 0; i < Constants.Rows; i++)
            {
                for (int j = 0; j < Constants.Columns; j++)
                {
                    bonusCreated[i, j] = false;
                }
            }

            // loop throw all found matches
            List <GameObject> matches = new List <GameObject>();
            foreach (var item in matchesInfos)
            {
                // check if bonus should be created
                if (item.Matches >= Constants.MinimumMatchesForBonus)
                {
                    bool bonus = true;
                    foreach (var go in item.MatchedCandy)
                    {
                        if (bonusCreated[go.GetComponent <Shape>().Row, go.GetComponent <Shape>().Column] == true)
                        {
                            bonus = false;
                        }
                    }

                    if (bonus == true)
                    {
                        item.CreateBonus = true;

                        foreach (var go in item.MatchedCandy)
                        {
                            bonusCreated[go.GetComponent <Shape>().Row, go.GetComponent <Shape>().Column] = true;
                        }
                    }
                }
                // save each object to save it then to totalMatches
                matches.AddRange(item.MatchedCandy);
            }

            totalMatches = matches;

            timesRun++;
        }

        state = GameState.None;

        if (matchPerformed == true)
        {
            StartCheckForPotentialMatches();
        }
    }
示例#3
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(Constants.AnimationDuration, hitGo2.transform.position);
        hitGo2.transform.positionTo(Constants.AnimationDuration, hitGo.transform.position);
        yield return(new WaitForSeconds(Constants.AnimationDuration));

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

        var totalMatches = hitGomatchesInfo.MatchedCandy
                           .Union(hitGo2matchesInfo.MatchedCandy).Distinct();

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

            shapes.UndoSwap();
        }

        //if more than 3 matches and no Bonus is contained in the line, we will award a new Bonus
        bool addBonus = totalMatches.Count() >= Constants.MinimumMatchesForBonus &&
                        !BonusTypeUtilities.ContainsDestroyWholeRowColumn(hitGomatchesInfo.BonusesContained) &&
                        !BonusTypeUtilities.ContainsDestroyWholeRowColumn(hitGo2matchesInfo.BonusesContained);

        Shape hitGoCache = null;

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

        int timesRun = 1;

        while (totalMatches.Count() >= Constants.MinimumMatches)
        {
            //increase score
            IncreaseScore((totalMatches.Count() - 2) * Constants.Match3Score);

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

            soundManager.PlayCrincle();

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

            //check and instantiate Bonus if needed
            if (addBonus)
            {
                CreateBonus(hitGoCache);
            }

            addBonus = false;

            //get the columns that we had a collapse
            var columns = totalMatches.Select(go => go.GetComponent <Shape>().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(Constants.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.None;
        StartCheckForPotentialMatches();
    }
示例#4
0
    private IEnumerator FindMatchesAndCollapse(RaycastHit2D hit2)
    {
        //get the second item that was part of the swipe
        var hitGo2 = hit2.collider.gameObject;

        if (hitGo2.GetComponent <Shape>().isBanned)
        {
            state = GameState.None;
            yield break;
        }
        shapes.Swap(hitGo, hitGo2);
        movesLeft--;
        if (movesLeft <= 0)
        {
            Update();
        }
        howManyLeft.text = Left();
        int column1, row1;

        column1 = hitGo.GetComponent <Shape>().Column;
        row1    = hitGo.GetComponent <Shape>().Row;
        int column2, row2;

        column2 = hitGo2.GetComponent <Shape>().Column;
        row2    = hitGo2.GetComponent <Shape>().Row;
        //move the swapped ones
        hitGo.transform.positionTo(Constants.AnimationDuration, hitGo2.transform.position);
        string hitGoName = hitGo.name;

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

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

        var totalMatches = hitGomatchesInfo.MatchedCandy
                           .Union(hitGo2matchesInfo.MatchedCandy).Distinct();

        //if user's swap didn't create at least a 3-match, undo their swap

        /*if (totalMatches.Count() < Constants.MinimumMatches)
         * {
         *  hitGo.transform.positionTo(Constants.AnimationDuration, hitGo2.transform.position);
         *  hitGo2.transform.positionTo(Constants.AnimationDuration, hitGo.transform.position);
         *  yield return new WaitForSeconds(Constants.AnimationDuration);
         *
         *  shapes.UndoSwap();
         * }*/

        //if more than 3 matches and no Bonus is contained in the line, we will award a new Bonus
        bool addBonus = totalMatches.Count() >= Constants.MinimumMatchesForBonus &&
                        !BonusTypeUtilities.ContainsDestroyWholeRowColumn(hitGomatchesInfo.BonusesContained) &&
                        !BonusTypeUtilities.ContainsDestroyWholeRowColumn(hitGo2matchesInfo.BonusesContained);

        Shape hitGoCache = null;

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

        int timesRun = 1;

        while (totalMatches.Count() >= Constants.MinimumMatches)
        {
            //increase score
            //TODO add conditions to score increasement
            var a = totalMatches.ElementAt(0).ToString();
            switch (Constants.Mode)
            {
            case 1:
            {
                Increase(totalMatches, timesRun);
                break;
            }

            case 2:
            {
                Increase(totalMatches, timesRun);
                break;
            }

            case 3:
            {
                string color;
                switch (Constants.CurrentLevel)
                {
                case 3:
                    color = "purple";
                    break;

                case 8:
                    color = "blue";
                    break;

                case 13:
                    color = "green";
                    break;

                case 18:
                    color = "pink";
                    break;

                case 23:
                    color = "orange";
                    break;

                default:
                    color = "err";
                    break;
                }
                if (hitGoName.Contains(color))
                {
                    Increase(totalMatches, timesRun);
                }
                break;
            }

            case 4:
            {
                if (isInArea(pointsArea1, pointsArea2, new Vector2(column1, row1)) ||
                    isInArea(pointsArea1, pointsArea2, new Vector2(column2, row2)))
                {
                    Increase(totalMatches, timesRun);
                }
                break;
            }

            case 5:
            {
                foreach (var var in totalMatches)
                {
                    if (isInArea(bannedArea1, bannedArea2, new Vector2(var.GetComponent <Shape>().Column, var.GetComponent <Shape>().Row)))
                    {
                        Increase(totalMatches, timesRun);
                        break;
                    }
                }

                /*
                 * if (isInArea(0, 0, 4, 4, column1, row1) ||
                 *  isInArea(0, 0, 4, 4, column2, row2))
                 * {
                 *  Increase(totalMatches, timesRun);
                 * }*/
                break;
            }

            default:
            {
                Increase(totalMatches, timesRun);
                break;
            }
            }
            soundManager.PlayCrincle();

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

            //check and instantiate Bonus if needed
            if (addBonus)
            {
                CreateBonus(hitGoCache);
            }

            addBonus = false;

            //get the columns that we had a collapse
            var columns = totalMatches.Select(go => go.GetComponent <Shape>().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(Constants.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.None;

        StartCheckForPotentialMatches();
    }
示例#5
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(Constants.AnimationDuration, hitGo2.transform.position);
        hitGo2.transform.positionTo(Constants.AnimationDuration, hitGo.transform.position);
        yield return(new WaitForSeconds(Constants.AnimationDuration));

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

        var totalMatches = hitGomatchesInfo.MatchedFood
                           .Union(hitGo2matchesInfo.MatchedFood).Distinct();

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

            shapes.UndoSwap();
        }

        int timesRun = 1;

        while (totalMatches.Count() >= Constants.MinimumMatches)
        {
            //increase score
            IncreaseScore((totalMatches.Count() - 2) * Constants.Match3Score);

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

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

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

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

            int maxDistance = Mathf.Max(collapsedFoodInfo.MaxDistance, newFoodInfo.MaxDistance);

            MoveAndAnimate(newFoodInfo.AlteredFood, maxDistance);
            MoveAndAnimate(collapsedFoodInfo.AlteredFood, 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(collapsedFoodInfo.AlteredFood).
                           Union(shapes.GetMatches(newFoodInfo.AlteredFood)).Distinct();



            timesRun++;
        }

        state = GameState.None;
        StartCheckForPotentialMatches();
    }
示例#6
0
    private IEnumerator FindMatchesAndCollapse(RaycastHit2D hit2)
    {
        Vector3 t = hitGo.transform.position;

        //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(Constants.AnimationDuration, hitGo2.transform.position);
        //hitGo2.transform.positionTo(Constants.AnimationDuration, hitGo.transform.position);
        yield return(new WaitForSeconds(Constants.AnimationDuration));

        Debug.Log("pos=" + t);

        int combo = getCombo(hitGo, hitGo2);

        if (combo < 0)
        {
            Debug.Log("moving from pos=" + hitGo.transform.position + "to pos=" + t);
            hitGo.transform.positionTo(Constants.AnimationDuration, t);
            // hitGo2.transform.positionTo(Constants.AnimationDuration, hitGo.transform.position);
            yield return(new WaitForSeconds(Constants.AnimationDuration));

            Debug.Log("combo not recognized, type1 is" + hitGo.GetComponent <Shape>().Type + " type2 is " + hitGo2.GetComponent <Shape>().Type);
        }
        else
        {
            GameObject newCandy = Instantiate(CandyPrefabs[levels[currentLevelIndex].indexOfFirstElement + combo], hitGo2.transform.position, Quaternion.identity)
                                  as GameObject;
            newCandy.GetComponent <Shape>().Row    = hitGo2.GetComponent <Shape>().Row;
            newCandy.GetComponent <Shape>().Column = hitGo2.GetComponent <Shape>().Column;
            newCandy.GetComponent <Shape>().Type   = combo;
            shapes.Remove(hitGo);
            RemoveFromScene(hitGo);

            ///If this is a last item, remove it from the board and score
            if (combo >= levels[currentLevelIndex].firstComplete)
            {
                shapes.Remove(hitGo2);
                //RemoveFromScene(newCandy);
                newCandy.GetComponent <Shape>().eject();
                score += 5;
            }
            else
            {
                shapes.setShape(newCandy);
            }
            //shapes.Remove(hitGo2);
            RemoveFromScene(hitGo2);
            //hitGo2.GetComponent<Sprite>().texture = CandyPrefabs[combo].GetComponent<Sprite>().texture;
            //shapes.changeTo(newCandy, combo);



            //var collapsedCandyInfo = shapes.Collapse(hitGo.GetComponent<Shape>().Column);
            var collapsedCandyInfo = shapes.Collapse();

            var newCandyInfo = CreateNewCandyInSpecificColumns();

            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));

            var matches = shapes.getMatches();
            foreach (GameObject go in matches)
            {
                shapes.Remove(go);
                RemoveFromScene(go);
            }
            //var collapsedCandyInfo = shapes.Collapse(hitGo.GetComponent<Shape>().Column);
            collapsedCandyInfo = shapes.Collapse();

            newCandyInfo = CreateNewCandyInSpecificColumns();

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

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

        /*
         * //get the matches via the helper methods
         * var hitGomatchesInfo = shapes.GetMatches(hitGo);
         * var hitGo2matchesInfo = shapes.GetMatches(hitGo2);
         *
         * var totalMatches = hitGomatchesInfo.MatchedCandy
         *  .Union(hitGo2matchesInfo.MatchedCandy).Distinct();
         *
         * //if user's swap didn't create at least a 3-match, undo their swap
         * if (totalMatches.Count() < Constants.MinimumMatches)
         * {
         *  hitGo.transform.positionTo(Constants.AnimationDuration, hitGo2.transform.position);
         *  hitGo2.transform.positionTo(Constants.AnimationDuration, hitGo.transform.position);
         *  yield return new WaitForSeconds(Constants.AnimationDuration);
         *
         *  shapes.UndoSwap();
         * }
         *
         * //if more than 3 matches and no Bonus is contained in the line, we will award a new Bonus
         * bool addBonus = totalMatches.Count() >= Constants.MinimumMatchesForBonus &&
         *  !BonusTypeUtilities.ContainsDestroyWholeRowColumn(hitGomatchesInfo.BonusesContained) &&
         *  !BonusTypeUtilities.ContainsDestroyWholeRowColumn(hitGo2matchesInfo.BonusesContained);
         *
         * Shape hitGoCache = null;
         * if (addBonus)
         * {
         *  //get the game object that was of the same type
         *  var sameTypeGo = hitGomatchesInfo.MatchedCandy.Count() > 0 ? hitGo : hitGo2;
         *  hitGoCache = sameTypeGo.GetComponent<Shape>();
         * }
         *
         * int timesRun = 1;
         * while (totalMatches.Count() >= Constants.MinimumMatches)
         * {
         *  //increase score
         *  IncreaseScore((totalMatches.Count() - 2) * Constants.Match3Score);
         *
         *  if (timesRun >= 2)
         *      IncreaseScore(Constants.SubsequentMatchScore);
         *
         *  soundManager.PlayCrincle();
         *
         *  foreach (var item in totalMatches)
         *  {
         *      shapes.Remove(item);
         *      RemoveFromScene(item);
         *  }
         *
         *
         *
         *  addBonus = false;
         *
         * //get the columns that we had a collapse
         * var columns = totalMatches.Select(go => go.GetComponent<Shape>().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(Constants.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.None;
        StartCheckForPotentialMatches();
    }
示例#7
0
    private IEnumerator FindMatchesAndCollapse(GameObject hitGo2)
    {
        bool addBonus = false;

        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;

        shapes.Swap(hitGo, hitGo2);

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

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

        var totalMatches = hitGomatchesInfo.MatchedBlock
                           .Union(hitGo2matchesInfo.MatchedBlock).Distinct();

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

            shapes.UndoSwap();
        }

        //if more than 3 matches and no Bonus is contained in the line, we will award a new Bonus
        if ((hitGomatchesInfo.MatchedBlock.Count() >= Constants.MinimumMatchesForBonus || hitGo2matchesInfo.MatchedBlock.Count() >= Constants.MinimumMatchesForBonus) && !timedTurns)
        {
            addBonus = true;
            turnTime = 30f;
            StartCoroutine(DisplayText(bonusText));
        }

        int timesRun = 1; //can be used for subsequent matching bonus point

        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
            var columns = totalMatches.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();

            //if we have not hit bonus and we don't have timed turns, change turn
            if (!timedTurns && !addBonus && totalMatches.Count() < Constants.MinimumMatches)
            {
                ChangeTurn();
            }

            timesRun++;
        }

        state = GameState.None;
        StartCheckForPotentialMatches();
    }