示例#1
0
    /// <summary>
    /// Creates a string with the contents of the shapes array
    /// </summary>
    /// <param name="shapes"></param>
    /// <returns></returns>
    public static string GetArrayContents(ShapesArray shapes)
    {
        string x = string.Empty;

        for (int row = Constants.Rows - 1; row >= 0; row--)
        {
            for (int column = 0; column < Constants.Columns; column++)
            {
                if (shapes[row, column] == null)
                {
                    x += "NULL  |";
                }
                else
                {
                    var shape = shapes[row, column].GetComponent <Shape>();
                    x += shape.Row.ToString("D2")
                         + "-" + shape.Column.ToString("D2");

                    x += shape.Type;

                    if (BonusTypeUtilities.ContainsDestroyWholeRowColumn(shape.Bonus))
                    {
                        x += "B";
                    }
                    else
                    {
                        x += " ";
                    }

                    x += " | ";
                }
            }
            x += Environment.NewLine;
        }
        return(x);
    }
示例#2
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();
    }
示例#3
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();
    }