Esempio n. 1
0
    /// <summary>
    /// 정해진 그리드 내에 None Chamber를 생성 -> 불필요 메소드
    /// </summary>
    //private void makeNoneChamber()
    //{
    //    for (int i = 0; i < NumOfChamberInVertical; i++)
    //    {
    //        for (int j = 0; j < NumOfChamberInHorizontal; j++)
    //        {
    //            ChamberPosition.Add(new Vector2Int(i, j), new CChamber(EChamberType.None, new Vector2Int(i, j)));
    //        }
    //    }
    //}

    /// <summary>
    /// 필수 경로를 생성
    /// </summary>
    private void makeEssentialPath()
    {
        Vector2Int currentPosition, nextPosition;

        Vector2Int[] adjacentPosition;
        // 필수 경로 시작 지점
        currentPosition = StartChamberPos = new Vector2Int(0, (int)Random.Range(0.0f, NumOfChamberInVertical));
        //ChamberPosition[currentPosition].ChamberType = EChamberType.Essential;
        ChamberPosition.Add(currentPosition, new CChamber(EChamberType.Essential, currentPosition));
        // 필수 경로 인접 지점
        adjacentPosition = getAdjacentPath(currentPosition, true);
        nextPosition     = adjacentPosition[(int)Random.Range(0.0f, adjacentPosition.Length)];
        //ChamberPosition[nextPosition].ChamberType = EChamberType.Essential;
        ChamberPosition.Add(nextPosition, new CChamber(EChamberType.Essential, nextPosition));
        addFromCurrentToNextChamberPassage(currentPosition, nextPosition);
        currentPosition = nextPosition;
        // 그리드의 맨 오른쪽 위치 까지 진행
        while (currentPosition.x != NumOfChamberInHorizontal - 1)
        {
            adjacentPosition = getAdjacentPath(currentPosition, true);

            nextPosition = adjacentPosition[(int)Random.Range(0.0f, adjacentPosition.Length)];
            //ChamberPosition[nextPosition].ChamberType = EChamberType.Essential;
            ChamberPosition.Add(nextPosition, new CChamber(EChamberType.Essential, nextPosition));
            addFromCurrentToNextChamberPassage(currentPosition, nextPosition);
            currentPosition = nextPosition;
        }
        // 도착 지점 설정
        EndChamberPos = currentPosition;
    }
Esempio n. 2
0
    /// <summary>
    /// 생성된 필수 경로를 기준으로 더미 경로를 생성한다.
    /// </summary>
    /// <param name="start"></param>
    private void makeDummyPath(Vector2Int start)
    {
        // 해당 Chamber가 필수 경로 상의 Chamber인 경우
        if (ChamberPosition[start].ChamberType == EChamberType.Essential && ChamberPosition[start].NextChamberPosition.Count != 0)
        {
            Debug.Log(start);
            // 다음 필수경로를 대상으로 실행
            makeDummyPath(ChamberPosition[start].NextChamberPosition[0]);
        }

        int possibility = (int)Random.Range(0.0f, 5.0f);

        Vector2Int[] adjacentChambers = getAdjacentPath(start, false);

        // 인접한 Chamber가 존재하지 않는 경우
        if (adjacentChambers.Length == 0)
        {
            return;
        }
        int index = (int)Random.Range(0.0f, adjacentChambers.Length);

        //ChamberPosition[adjacentChambers[index]].ChamberType = EChamberType.Dummy;
        ChamberPosition.Add(adjacentChambers[index], new CChamber(EChamberType.Dummy, adjacentChambers[index]));
        addFromCurrentToNextChamberPassage(start, adjacentChambers[index]);

        Debug.Log(adjacentChambers[index]);
        // 40%의 확률로 길이 확장
        if (possibility == 0 || possibility == 1 || possibility == 2)
        {
            makeDummyPath(adjacentChambers[index]);
        }  // 40% 확률로 새로운 길 분열
        else if (possibility == 3)
        {
            makeDummyPath(adjacentChambers[index]);
            makeDummyPath(start);
        }
    }