Beispiel #1
0
    /// ------- Funções de fazer a linha cair e merge com corotina ----------
    ///

    IEnumerator WaitTillBlockExplode(BlocoInstance bloco, int index, bool alone)
    {
        bloco.canDestroy = false;

        while (!bloco.canDestroy)
        {
            yield return(new WaitForEndOfFrame());
        }

        blocksPattern[index] = 0;

        if (!alone)
        {
            StartCoroutine(Merge(index - 1, false, true));
        }
    }
Beispiel #2
0
    /// ------- Funções de merge ----------
    ///

    // Verifica se tem merges a serem feitos
    // faz isso até que todos os merges da linha foram completados
    public bool MergeCheck(int blockIndex)
    {
        BlocoInstance blockInfo = blockList[blockIndex].GetComponent <BlocoInstance>();

        // Caso 4: o bloco está em seu ultimo valor e tem blocos ao lado
        if (blocksPattern[blockIndex] == blockList[blockIndex].GetComponent <BlocoInstance>().MaxBlockValue)
        {
            // Verifica se há blocos à direita e à esquerda --- puxa para direita porque sim
            if ((blockIndex != MaxNumOfBlocksPerLine - 1 && blockIndex != 0) && (blocksPattern[blockIndex - 1] != 0 && blocksPattern[blockIndex + 1] != 0))
            {
                StartCoroutine(WaitTillBlockExplode(blockList[blockIndex].GetComponent <BlocoInstance>(), blockIndex, false));
                return(true);
            }

            // Caso 1: o bloco está no centro e está entre dois blocos
        }
        else if ((blockIndex != 0 && blockIndex != MaxNumOfBlocksPerLine - 1) && (blocksPattern[blockIndex - 1] != 0 && blocksPattern[blockIndex + 1] != 0))
        {
            // - Verifica se há blocos à esquerda e direita são iguais a ele -> caso sim, aumenta seu valor e some com os dois do lado, puxa TODOS para o centro
            if ((blocksPattern[blockIndex - 1] == blocksPattern[blockIndex]) && (blocksPattern[blockIndex + 1] == blocksPattern[blockIndex]))
            {
                int newValue = blockList[blockIndex].GetComponent <BlocoInstance>().getBlockValue() * 2;
                blockList[blockIndex].GetComponent <BlocoInstance>().updateBlockValue(newValue);
                StartCoroutine(WaitForUpgradeMerge(blockIndex, true, true));
                return(true);

                // - Verifica se há blocos à esquerda iguais a ele -> caso sim, aumenta seu valor e some com o da esquerda e puxa todos os blocos da ESQUERDA
            }
            else if (blocksPattern[blockIndex - 1] == blocksPattern[blockIndex])
            {
                int newValue = blockList[blockIndex].GetComponent <BlocoInstance>().getBlockValue() * 2;
                blockList[blockIndex].GetComponent <BlocoInstance>().updateBlockValue(newValue);
                StartCoroutine(WaitForUpgradeMerge(blockIndex, true, false));
                return(true);

                // - Verifica se há blocos à direita iguais a ele -> caso sim, aumenta seu valor e some com o da direita e puxa todos os blocos da DIREITA
            }
            else if (blocksPattern[blockIndex + 1] == blocksPattern[blockIndex])
            {
                int newValue = blockList[blockIndex].GetComponent <BlocoInstance>().getBlockValue() * 2;
                blockList[blockIndex].GetComponent <BlocoInstance>().updateBlockValue(newValue);
                StartCoroutine(WaitForUpgradeMerge(blockIndex, false, true));
                return(true);
            }

            // Caso 2: o bloco atingido foi o da extrema esquerda ou não é o ultimo bloco e tem blocos à direita
        }
        else if (blockIndex == 0 || (blockIndex != MaxNumOfBlocksPerLine - 1 && blocksPattern[blockIndex + 1] != 0))
        {
            // - Verifica se há blocos à direita iguais a ele-> caso sim, aumenta seu valor e some com a da direita e puxa todos todos os blocos da DIREITA
            if (blocksPattern[blockIndex + 1] == blocksPattern[blockIndex])
            {
                int newValue = blockList[blockIndex].GetComponent <BlocoInstance>().getBlockValue() * 2;
                blockList[blockIndex].GetComponent <BlocoInstance>().updateBlockValue(newValue);
                StartCoroutine(WaitForUpgradeMerge(blockIndex, false, true));
                return(true);
            }

            // Caso 3: o bloco atingido foi o da extrema direita ou não é o primeiro bloco e tem blocos à esquerda
        }
        else if (blockIndex == MaxNumOfBlocksPerLine - 1 || (blockIndex != 0 && blocksPattern[blockIndex - 1] != 0))
        {
            // - Verifica se há blocos à esquerda iguais a ele -> caso sim, aumenta seu valor e some com a da esquerda e puxa todos os blocas da ESQUERDA
            if (blocksPattern[blockIndex - 1] == blocksPattern[blockIndex])
            {
                int newValue = blockList[blockIndex].GetComponent <BlocoInstance>().getBlockValue() * 2;
                blockList[blockIndex].GetComponent <BlocoInstance>().updateBlockValue(newValue);
                StartCoroutine(WaitForUpgradeMerge(blockIndex, true, false));
                return(true);
            }

            // Caso 5: o bloco está sem nenhum bloco ao lado
            // meio se tem em a direita ou a esquerda
            // extrema esquerda se tem ao lado direito
            // extrema direita se tem ao lado esquerdo
        }
        else if (((blockIndex != 0 && blockIndex != MaxNumOfBlocksPerLine - 1) && (blocksPattern[blockIndex - 1] == 0 && blocksPattern[blockIndex + 1] == 0)) ||
                 (blockIndex == 0 && blocksPattern[blockIndex + 1] == 0) || (blockIndex == MaxNumOfBlocksPerLine - 1 && blocksPattern[blockIndex - 1] == 0))
        {
            Debug.Log("É um bloco sozinho");

            blockList[blockIndex].GetComponent <BlocoInstance>().updateBlockValue(16);
            StartCoroutine(WaitTillBlockExplode(blockList[blockIndex].GetComponent <BlocoInstance>(), blockIndex, true));
        }

        // Caso 6: o bloco está upgradou e não tem merge - nada acontece feijoada
        return(false);
    }