Files
BABA_YAGA/Assets/Scripts/GameSetup/Maze/Crawler.cs
scove 3a687a4d58 Refactor maze scripts: namespaces & cleanup
Move Maze-related scripts into the Hallucinate.GameSetup.Maze namespace and perform a broad refactor and cleanup. Make MapLocation a readonly struct, add Corridor/Wall/Path constants, and convert Maze into a clearer base class with serialized fields (width, depth, scale, mapParentObject), proper initialization, virtual Generate, and safer DrawMap behavior. Update neighbor-count helpers, tighten method visibility, and improve algorithm implementations (Crawler, Prims, Recursive, Wilsons) to use the new constants and more robust logic (including logging and loop guards). Add a Fisher–Yates Shuffle extension with a static RNG under Hallucinate.GameSetup.Maze.Extensions. Also update IDE metadata (.idea encodings.xml and workspace.xml) to record file encodings and some project settings.
2026-04-21 21:44:26 +07:00

71 lines
2.0 KiB
C#

using UnityEngine;
namespace Hallucinate.GameSetup.Maze
{
/// <summary>
/// A maze generation algorithm that "crawls" through the grid in a semi-random walk.
/// It creates long, winding corridors by moving vertically or horizontally.
/// </summary>
public class Crawler : Maze
{
/// <summary>
/// Orchestrates the crawling generation.
/// (Currently empty as per original procedural logic).
/// </summary>
public override void Generate()
{
// Implementation can be expanded as needed.
}
/// <summary>
/// Performs a vertical crawl starting from a random X position at the bottom.
/// </summary>
protected void CrawlV()
{
bool done = false;
int x = Random.Range(1, width - 1);
int z = 1;
while (!done)
{
map[x, z] = Corridor;
if (Random.Range(0, 100) < 50)
{
x += Random.Range(-1, 2);
}
else
{
z += Random.Range(0, 2);
}
done |= (x < 1 || x >= width - 1 || z < 1 || z >= depth - 1);
}
}
/// <summary>
/// Performs a horizontal crawl starting from a random Z position at the left.
/// </summary>
protected void CrawlH()
{
bool done = false;
int x = 1;
int z = Random.Range(1, depth - 1);
while (!done)
{
map[x, z] = Corridor;
if (Random.Range(0, 100) < 50)
{
x += Random.Range(0, 2);
}
else
{
z += Random.Range(-1, 2);
}
done |= (x < 1 || x >= width - 1 || z < 1 || z >= depth - 1);
}
}
}
}