Пример #1
0
    // Start is called before the first frame update
    void Start()
    {
        dot   = this.gameObject.GetComponent <Hexa.Dot>();
        board = FindObjectOfType <Hexa.Board>();

        // 주변을 체크해
        CheckNearNodes();
    }
Пример #2
0
    // 주변 노드들 탐지
    public void CheckNearNodes_Hexa()
    {
        Hexa.Dot   dot       = this.gameObject.GetComponent <Hexa.Dot>();
        Hexa.Board hexaBoard = board.GetComponent <Hexa.Board>();

        if (dot != null)
        {
            GameObject nodeObj = hexaBoard.nodes[dot.column][dot.row];

            // 차감 횟수가 0, 즉 다 터졌으면
            if (count <= 0)
            {
                // 보드에서 장애물 갯수를 하나 줄이고
                hexaBoard.obstacles.Dequeue();
                // 나의 매치 상태를 true로 -> 사라질때 처리를 Dot과 한꺼번에
                dot.isMatched = true;
            }

            // 나의 node정보가 있다면, 혹시모를 null 오류 방지
            if (nodeObj != null)
            {
                Hexa.Node node = nodeObj.GetComponent <Hexa.Node>();

                for (int i = 0; i < 6; i++)
                {
                    // 주변 노드가 있다면
                    if (node.nearNodes[i] != null)
                    {
                        // 주변에서 블럭이 터지면
                        if (node.nearNodes[i].GetComponent <Hexa.Node>().dot == null || node.nearNodes[i].GetComponent <Hexa.Node>().dot.GetComponent <Hexa.Dot>().isMatched == true)
                        {
                            // 나의 색깔을 0.6%정도로 변화시키고
                            this.gameObject.GetComponent <SpriteRenderer>().color *= 0.6f;
                            // 차감 횟수를 낮춘 후
                            count--;
                            // 나가, 왜? 주변에서 여러개가 한꺼번에 터져도 횟수는 한번만 차감되기 때문.
                            break;
                        }
                    }
                }
            }
        }
    }
Пример #3
0
        // 보드 섞기
        IEnumerator ShakeBoard()
        {
            yield return(new WaitForSeconds(0.5f));

            List <GameObject> newDots = new List <GameObject>();

            Node topNode = nodes[(int)totalWidth / 2][(int)maxHeight - 1].GetComponent <Node>();
            int  nCount  = 0;

            // 맨 위가 비어있지 않을 때, 즉 모두 다 찼을때
            if (topNode.dot != null && dots[topNode.column][topNode.row] != null)
            {
                for (int i = 0; i < dots.Count; i++)
                {
                    for (int j = 0; j < dots[i].Count; j++)
                    {
                        // 비어있지 않고 장애물이 아니면
                        if (dots[i][j] != null && dots[i][j].tag != "Obstacle")
                        {
                            // 새 dot 목록에 넣어
                            newDots.Add(dots[i][j]);
                        }
                    }
                }

                // 0.5초 기다리고
                yield return(new WaitForSeconds(0.5f));

                for (int i = 0; i < dots.Count; i++)
                {
                    for (int j = 0; j < dots[i].Count; j++)
                    {
                        // 새 dot 목록 중 랜덤으로 하나 선택
                        int dotToUse = Random.Range(0, newDots.Count);

                        int maxIteration = 0;

                        // 생성시 바로 터지게 겹치지 않는지 검사
                        while (MatchesAt(i, j, newDots[dotToUse]) && maxIteration < 100)
                        {
                            dotToUse = Random.Range(0, newDots.Count);
                            maxIteration++;
                        }
                        maxIteration = 0;

                        Dot dot = newDots[dotToUse].GetComponent <Dot>();

                        // 해당 위치에 장애물이 없으면 새로 배치
                        if (dots[i][j].tag != "Obstacle")
                        {
                            dot.column = i;
                            dot.row    = j;
                            dots[i][j] = newDots[dotToUse];
                            nodes[i][j].GetComponent <Node>().dot = newDots[dotToUse];
                            newDots.Remove(newDots[dotToUse]);
                        }
                    }
                }
            }

            if (IsDeadLocked())
            {
                StartCoroutine("ShakeBoard");
            }
        }