Exemple #1
0
    void GenerateSquares(DungeonSquare[,] squares)
    {
        for (int i = 0; i < length; i++)
        {
            GameObject row = new GameObject("Row" + (i + 1));
            row.transform.parent   = transform;
            row.transform.position = transform.position;

            for (int j = 0; j < width; j++)
            {
                if (squares[i, j] == null)
                {
                    continue;
                }

                connectLogic.Survey(i, j, squares);

                #region Setup Square in Hierarchy
                squares[i, j].layout = connectLogic.BuildLayout(squares[i, j].adjacents);
                GameObject sq = squares[i, j].layout;

                sq.transform.parent        = transform;
                sq.transform.localPosition = coordinates[i, j];
                sq.transform.parent        = row.transform;

                sq.name = "Sq" + (j + 1);
                #endregion
            }
        }
    }
Exemple #2
0
    void Generate()
    {
        ClearMaze();

        if (numberOfSquares > 0)
        {
            AddSquare(0, 0);
        }
        int num = 1;

        if (sprawl)
        {
            while (num < numberOfSquares)
            {
                vacancies = RefreshVacancies();
                int rand = Random.Range(0, vacancies.Count);

                //If square has full adjacencies, make it less likely to fill
                int adjCount = 1;
                for (int i = 0; i < vacancies[rand].adjacents.Length; i++)
                {
                    if (coordinatesToSquare.ContainsKey(vacancies[rand].adjacents[i].id))
                    {
                        adjCount++;
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                if (adjCount == vacancies[rand].adjacents.Length)
                {
                    continue;
                }

                AddSquare(vacancies[rand].xCoord, vacancies[rand].yCoord);

                num++;
            }
        }
        else
        {
            while (num < numberOfSquares)
            {
                vacancies = RefreshVacancies();
                int rand = Random.Range(0, vacancies.Count);

                AddSquare(vacancies[rand].xCoord, vacancies[rand].yCoord);

                num++;
            }
        }

        foreach (DungeonSquare sq in coordinatesToSquare.Values)
        {
            sq.layout = connectLogic.BuildLayout(sq.adjacents);

            Transform sqTrans = sq.layout.transform;
            sqTrans.parent        = transform;
            sqTrans.localPosition = new Vector3(sq.xCoord * squareSize, 0, sq.yCoord * squareSize);
        }
    }