Exemplo n.º 1
0
    private IEnumerator MoveDownNodes()
    {
        yield return(new WaitForSeconds(ConstantManager.DELAY_TIME));

        int  numNullRow = 0;
        bool blackNode;
        int  i = 0, j = 0;

        for (i = 0; i < width; i++)
        {
            blackNode = false;
            for (j = 0; j < height; j++)
            {
                if (allCreatedNodes[i, j] == null)
                {
                    numNullRow++;
                }
                else if (numNullRow > 0)
                {
                    if (!ConstantManager.GetMapIndexStatus(i, j))
                    {
                        blackNode = true;
                        if (j > 0 && j < height - 1 && ConstantManager.GetMapIndexStatus(i, j - 1) && allCreatedNodes[i, j - 1] != null)
                        {
                            numNullRow = 0;
                        }
                        else
                        {
                            numNullRow++;
                        }
                    }
                    else
                    {
                        allCreatedNodes[i, j].GetComponent <NodeController>().row -= numNullRow;
                        if (soundManager != null)
                        {
                            soundManager.PlaySound(SoundId.CREATE);
                        }
                        allCreatedNodes[i, j] = null;
                        if (blackNode)
                        {
                            numNullRow = 1;
                            blackNode  = false;
                        }
                        yield return(null);
                    }
                }
            }
            numNullRow = 0;
        }
        yield return(new WaitForSeconds(ConstantManager.DELAY_TIME));

        StartCoroutine(OnUpdateNodes());
    }
Exemplo n.º 2
0
    private GameObject CreateNode(int column, int row)
    {
        if (column < 0 || row < 0)
        {
            return(null);
        }
        Vector2    tempPos = new Vector2(column, row + offSet);
        GameObject gObjPrefab, gNode;
        Vector2    localScale;

        if (!ConstantManager.GetMapIndexStatus(column, row))
        {
            localScale = disableNodePrefab.transform.localScale;
            gNode      = Instantiate(disableNodePrefab, tempPos, Quaternion.identity) as GameObject;
            gNode.transform.SetParent(disableNodeRoot);
        }
        else
        {
            int randomType   = Random.Range(0, nodeTypes.Length);
            int maxIteration = 0;
            while (CheckNodeMatchesByMapIndex(column, row, nodeTypes[randomType]) && maxIteration < ConstantManager.MAX_ITERATION)
            {
                randomType = Random.Range(0, nodeTypes.Length);
                maxIteration++;
            }
            maxIteration = 0;
            gObjPrefab   = nodeTypes[randomType];
            localScale   = gObjPrefab.transform.localScale;
            gNode        = Instantiate(gObjPrefab, tempPos, Quaternion.identity) as GameObject;
            gNode.transform.SetParent(enableNodeRoot);
        }
        NodeController nodeController = gNode.GetComponent <NodeController>();

        if (nodeController != null)
        {
            nodeController.column = column;
            nodeController.row    = row;
        }
        else
        {
            Debug.LogError("Missing NodeController component at ( " + column + "-" + row + ")");
        }
        gNode.transform.localScale   = localScale;
        allCreatedNodes[column, row] = gNode;
        gNode.name = "(" + column + "-" + row + ")";
        return(gNode);
    }
Exemplo n.º 3
0
    private bool MoveDown()
    {
        if (!ConstantManager.GetMapIndexStatus(column, row - 1))
        {
            return(false);
        }
        targetNode   = mainNode.allCreatedNodes[column, row - 1];
        resumeRow    = row;
        resumeColumn = column;
        NodeController nodeController = targetNode.GetComponent <NodeController>();

        if (nodeController != null)
        {
            nodeController.row += 1;
        }
        row -= 1;
        return(true);
    }
Exemplo n.º 4
0
    private IEnumerator FindAllMatchesCo()
    {
        yield return(new WaitForSeconds(0.1f));

        if (mainNode != null)
        {
            for (int i = 0; i < mainNode.Width; i++)
            {
                for (int j = 0; j < mainNode.Height; j++)
                {
                    GameObject currentNode = mainNode.allCreatedNodes[i, j];
                    if (currentNode != null && ConstantManager.GetMapIndexStatus(i, j))
                    {
                        if (i > 0 && i < mainNode.Width - 1)
                        {
                            GameObject leftNode  = mainNode.allCreatedNodes[i - 1, j];
                            GameObject rightNode = mainNode.allCreatedNodes[i + 1, j];
                            if (leftNode != null && rightNode != null)
                            {
                                if (leftNode.tag == currentNode.tag && rightNode.tag == currentNode.tag)
                                {
                                    SetMatchedNodes(leftNode, currentNode, rightNode);
                                }
                            }
                        }

                        if (j > 0 && j < mainNode.Height - 1)
                        {
                            GameObject upNode   = mainNode.allCreatedNodes[i, j + 1];
                            GameObject downNode = mainNode.allCreatedNodes[i, j - 1];
                            if (upNode != null && downNode != null)
                            {
                                if (upNode.tag == currentNode.tag && downNode.tag == currentNode.tag)
                                {
                                    SetMatchedNodes(upNode, currentNode, downNode);
                                }
                            }
                        }
                    }
                }
            }
        }
    }