Esempio n. 1
0
    // Function that search the flipped list and return the the first not null flipped's TobleGem
    public FlippedGems getFlipped(TobleGem Gem)
    {
        FlippedGems flipGem = null;

        for (int i = 0; i < flipped.Count; i++)
        {
            if (flipped[i].OtherTobleGem(Gem) != null)
            {
                flipGem = flipped[i];
                break;
            }
        }

        return(flipGem);
    }
Esempio n. 2
0
    void Update()
    {
        // Update TobleFoods if they need to keep or stop moving
        FinishedUpdating = new List <TobleGem>();
        for (int i = 0; i < update.Count; i++)
        {
            TobleGem gem = update[i];
            if (gem != null && !gem.UpdateGem())
            {
                FinishedUpdating.Add(gem);
            }
        }

        // After moving the all the TobleFoods, it needs to check if there is or is not a match
        // And what to do on each case
        for (int i = 0; i < FinishedUpdating.Count; i++)
        {
            TobleGem    gem        = FinishedUpdating[i];
            FlippedGems flip       = getFlipped(gem);
            TobleGem    flippedGem = null;

            // Board's empty spaces that will need to fill in
            int x = gem.x;
            fills[x] = Mathf.Clamp(fills[x] - 1, 0, 8);

            // Get the connected matching list for the gem
            List <TobleGem> connected      = GetMatching(gem);
            List <TobleGem> flip_connected = new List <TobleGem>();
            // If it founds a match, adds the moving TobleFood
            if (connected.Count > 1)
            {
                connected.Add(gem);
            }

            // If there was a swap in this update
            bool itFlipped = (flip != null);
            if (itFlipped)
            {
                // Gets the connected matching list for the flipped gem
                flippedGem     = flip.OtherTobleGem(gem);
                flip_connected = GetMatching(flippedGem);

                // Adds moved TobleFood if there is a match
                if (flip_connected.Count > 1)
                {
                    flip_connected.Add(flippedGem);
                }
                connected.AddRange(flip_connected);
            }

            // If there is no matches
            if (connected.Count == 0)
            {
                // And TobleFoods were swapped
                if (itFlipped)
                {
                    FlipGems(gem, flippedGem, false, false); // Swap them back

                    // Reset hint
                    StopAllCoroutines();
                    if (pm != null)
                    {
                        pm.DyingLight();
                        StartCoroutine(pm.Coroutine_HighlightIt());
                    }
                }
            }
            else if (connected.Count > 2) // If there is matches
            {
                SFXManager.instance.PlaySFX(Clear);

                StopAllCoroutines(); // Matches stop shuffle

                // Reset Hint
                if (pm != null)
                {
                    pm.NoHighlight();
                }

                // Destroy matching TobleFoods that are connected
                foreach (TobleGem tobleGem in connected)
                {
                    if (tobleGem != null && !destroyed.Contains(tobleGem))
                    {
                        tobleGem.gameObject.tag = "TobleDestroyed";
                        tobleGem.Gem_a.SetBool("DestroyIt", true);
                        tobleGem.transform.SetAsLastSibling();
                        tobleGem.Gem_p.gameObject.SetActive(true);



                        // Points will be increased each round
                        int economy = (tobleGem.TobleSO.points + ((StatusManager.instance.next_round - 1) * tobleGem.TobleSO.points));

                        // If 3 or more toblefoods have already been destroyed, triple the points earned for each next destroyed
                        if (destroyed.Count > 2)
                        {
                            points_move += (3 * economy) * (int)combo;
                        }
                        else
                        {
                            points_move += economy * (int)combo;
                        }

                        combo += (float)1 / connected.Count; // Multiply points for each match done in one single swap

                        destroyed.Add(tobleGem);
                    }
                }
                combo = Mathf.Round(combo);
            }
            flipped.Remove(flip);
            update.Remove(gem);
        }
    }