Ejemplo n.º 1
0
    IEnumerator Cascade()
    {
        List <int> gemIndexes = new List <int>();

        foreach (Gem gem in disappearedGems)
        {
            if (!gemIndexes.Contains(gem.xIndex))
            {
                gemIndexes.Add(gem.xIndex);
            }
        }

        int gemCount = 0;

        foreach (int i in gemIndexes)
        {
            int wait = 0;
            for (int j = 0; j < boardHeigth; j++)
            {
                //look for null objects
                if (gems[i, j] != null)
                {
                    continue;
                }
                wait     += 1;
                gemCount += 1;

                Gem gem = disappearedGems[gemCount - 1];

                //reswap object out of border
                int index = 0;

                //Debug.Log("Cascade at : " + i +" Wait : "+wait +" Gem Count : " + (gemCount-1));


                PlaceGemAt(i, j, gem);
                gem.transform.position = new Vector3(i, j, 0);

                do
                {
                    //..make it directinal for optimization
                    RandomGemAt(gem);
                    index += 1;
                    if (index > 1001)
                    {
                        //Debug.LogWarning("Inf�nte Loop");
                        break;
                    }
                } while (CheckMatchesAt(gem).Count > 0);

                gem.transform.GetComponent <SpriteRenderer>().enabled = true;

                //fall to null point
                gem.Cascade(j, wait - 1);
            }
        }
        yield return(null);
    }