예제 #1
0
        // 해당 블럭이 터질 수 있는 환경인가?
        public bool CheckNearArea(int column, int row)
        {
            GameObject nodeObj = nodes[column][row];

            List <string> otherDotTags = new List <string>();

            Queue <GameObject> check_nodes = new Queue <GameObject>();

            if (nodeObj != null)
            {
                Node       node = nodeObj.GetComponent <Node>();
                GameObject dot  = node.dot;

                if (dot != null)
                {
                    // 근처에 나와 같은 색들이 있는 경우 해당 노드를 check_node에 미리 넣어놔
                    for (int i = 0; i < 6; i++)
                    {
                        if (node.nearNodes[i] != null)
                        {
                            if (node.nearNodes[i].GetComponent <Node>().dot != null)
                            {
                                if (node.nearNodes[i].GetComponent <Node>().dot.tag != "Obstacle")
                                {
                                    otherDotTags.Add(node.nearNodes[i].GetComponent <Node>().dot.tag);
                                }

                                if (node.nearNodes[i].GetComponent <Node>().dot.tag == dot.tag)
                                {
                                    check_nodes.Enqueue(node.nearNodes[i]);
                                }
                            }
                        }
                    }

                    // 주변에 나와 다르지만, 색이 같은 블럭들이 있나 체크
                    if (CheckNearTag(node.column, node.row))
                    {
                        return(true);
                    }

                    // 나와 색이 같은 블럭의 주변에 나 이외에 색이 같은 블럭들이 있나 체크
                    for (int i = 0; i < check_nodes.Count; i++)
                    {
                        // 체크 노드에서 꺼내서
                        GameObject checkNode      = check_nodes.Dequeue();
                        Node       checkNode_node = checkNode.GetComponent <Node>();

                        // 체크 노드의 주변을 검색
                        for (int j = 0; j < 6; j++)
                        {
                            if (checkNode_node.nearNodes[i] != null)
                            {
                                if (checkNode_node.nearNodes[i].GetComponent <Node>().dot != null)
                                {
                                    if (node.column != checkNode_node.nearNodes[i].GetComponent <Node>().column &&
                                        node.row != checkNode_node.nearNodes[i].GetComponent <Node>().row)
                                    {
                                        for (int k = 0; k < 6; k++)
                                        {
                                            if (node.GetComponent <Node>().nearNodes[k] != null)
                                            {
                                                // 체크 노드의 주변이지만, 검사중인 노드가 아니고
                                                if (node.GetComponent <Node>().nearNodes[k] != checkNode_node.nearNodes[i])
                                                {
                                                    // 색이 같은 경우 true
                                                    if (checkNode_node.dot.tag == checkNode_node.nearNodes[i].GetComponent <Node>().dot.tag)
                                                    {
                                                        return(true);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // 나와 색이 다른 블럭의 주변에 나와 색이 같은 블럭들이 있나 체크
                    if (CheckNearNode_NotSameTag(node.column, node.row))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #2
0
        // 모든 매치된 것들 찾기
        private IEnumerator FindAllMatchesCo()
        {
            // 0.2초 후
            yield return(new WaitForSeconds(0.2f));

            for (int i = 0; i < mBorad.nodes.Count; i++)
            {
                for (int j = 0; j < mBorad.nodes[i].Count; j++)
                {
                    Node       currentDot_node = mBorad.nodes[i][j].GetComponent <Node>();
                    GameObject currentDot      = currentDot_node.GetComponent <Node>().dot;

                    // 해당 노드의 블럭이 비어있지 않고, 장애물이 아니면
                    if (currentDot != null && currentDot.tag != "Obstacle")
                    {
                        // 해당 노드와 연결된 위, 아래 노드를 검사
                        GameObject upDot_node   = currentDot_node.nearNodes[(int)Dir.UP];
                        GameObject downDot_node = currentDot_node.nearNodes[(int)Dir.DOWN];

                        // 위, 아래 노드가 존재하면
                        if (upDot_node != null && downDot_node != null)
                        {
                            // 상 하
                            GameObject upDot   = upDot_node.GetComponent <Node>().dot;
                            GameObject downDot = downDot_node.GetComponent <Node>().dot;

                            // 위 아래 노드의 블럭이 존재하면
                            if (upDot != null && downDot != null)
                            {
                                // 위 아래 노드의 블럭의 태그가 현재 검사중인 블럭의 태그와 같다면
                                if (upDot.tag == currentDot.tag && downDot.tag == currentDot.tag)
                                {
                                    // 해당 블럭들 중에 특수블럭이 있다면, 이 특수블럭의 범위 내의 블럭들까지 리스트에 합쳐 (Union - 합집합)
                                    currentMatches.Union(IsRowBomb(upDot.GetComponent <Dot>(), currentDot.GetComponent <Dot>(), downDot.GetComponent <Dot>()));
                                    // 검사된 블럭들을 리스트에 집어넣어
                                    GetNearbyPieces(upDot, currentDot, downDot);
                                }
                            }
                        }

                        GameObject leftUpDot_node    = currentDot_node.nearNodes[(int)Dir.LEFT_UP];
                        GameObject rightDownDot_node = currentDot_node.nearNodes[(int)Dir.RIGHT_DOWN];

                        if (leftUpDot_node != null && rightDownDot_node != null)
                        {
                            // 좌상 우하
                            GameObject leftUpDot    = leftUpDot_node.GetComponent <Node>().dot;
                            GameObject rightDownDot = rightDownDot_node.GetComponent <Node>().dot;

                            if (leftUpDot != null && rightDownDot != null)
                            {
                                if (leftUpDot.tag == currentDot.tag && rightDownDot.tag == currentDot.tag)
                                {
                                    currentMatches.Union(IsRowBomb(leftUpDot.GetComponent <Dot>(), currentDot.GetComponent <Dot>(), rightDownDot.GetComponent <Dot>()));

                                    GetNearbyPieces(leftUpDot, currentDot, rightDownDot);
                                }
                            }
                        }

                        GameObject rightUpDot_node  = currentDot_node.nearNodes[(int)Dir.RIGHT_UP];
                        GameObject leftDownDot_node = currentDot_node.nearNodes[(int)Dir.LEFT_DOWN];

                        if (rightUpDot_node != null && leftDownDot_node != null)
                        {
                            // 우상 좌하
                            GameObject rightUpDot  = rightUpDot_node.GetComponent <Node>().dot;
                            GameObject leftDownDot = leftDownDot_node.GetComponent <Node>().dot;

                            if (rightUpDot != null && leftDownDot != null)
                            {
                                if (rightUpDot.tag == currentDot.tag && leftDownDot.tag == currentDot.tag)
                                {
                                    currentMatches.Union(IsRowBomb(rightUpDot.GetComponent <Dot>(), currentDot.GetComponent <Dot>(), leftDownDot.GetComponent <Dot>()));
                                    GetNearbyPieces(rightUpDot, currentDot, leftDownDot);
                                }
                            }
                        }
                    }
                }
            }
        }