728x90
void GenerateByBinaryTree()
{
// 일단 길을 다 막아버리는 작업
for (int y = 0; y < Size; y++)
{
for (int x = 0; x < Size; x++)
{
if (x % 2 == 0 || y % 2 == 0)
Tile[y, x] = TileType.Wall;
else
Tile[y, x] = TileType.Empty;
}
}
// 랜덤으로 우측 혹은 아래로 길을 뚫는 작업
Random rand = new Random();
for (int y = 0; y < Size; y++)
{
for (int x = 0; x < Size; x++)
{
if (x % 2 == 0 || y % 2 == 0) continue;
if (y == Size - 2 && x == Size - 2) continue;
if (y == Size - 2)
{
Tile[y, x + 1] = TileType.Empty;
continue;
}
if (x == Size - 2)
{
Tile[y + 1, x] = TileType.Empty;
continue;
}
if (rand.Next(0, 2) == 0) Tile[y, x + 1] = TileType.Empty;
else Tile[y + 1, x] = TileType.Empty;
}
}
}
728x90
'기타 기술 > C#' 카테고리의 다른 글
ResourceManager (0) | 2023.08.12 |
---|---|
Singleton pattern (0) | 2023.08.12 |
NavMeshAgent (0) | 2023.08.11 |
ObjectPool Dictionary (0) | 2023.08.02 |
LoadingScene (0) | 2023.07.07 |