public void CreateDenseMaze(csDungeon dungeon) { Vector2 currentLocation = dungeon.PickRandomCellAndFlagItAsVisited(); csDungeonCell.DirectionType previousDirection = csDungeonCell.DirectionType.North; while (!dungeon.AllCellsAreVisited) { csDirectionPicker directionPicker = new csDirectionPicker(); directionPicker.Constructor(previousDirection, changeDirectionModifier); csDungeonCell.DirectionType direction = directionPicker.GetNextDirection(); while (!dungeon.HasAdjacentCellInDirection(currentLocation, direction) || dungeon.AdjacentCellInDirectionIsVisited(currentLocation, direction)) { if (directionPicker.HasNextDirection) { direction = directionPicker.GetNextDirection(); } else { currentLocation = dungeon.GetRandomVisitedCell(currentLocation); // Get a new previously visited location directionPicker = new csDirectionPicker(); directionPicker.Constructor(previousDirection, changeDirectionModifier); // Reset the direction picker direction = directionPicker.GetNextDirection(); // Get a new direction } } currentLocation = dungeon.CreateCorridor(currentLocation, direction); dungeon.FlagCellAsVisited(currentLocation); previousDirection = direction; } }