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; } }
public bool HasAdjacentCellInDirection(Vector2 location, csDungeonCell.DirectionType direction) { // Check that the location falls within the bounds of the map if (!Bounds.Contains(location)) { return(false); } // Check if there is an adjacent cell in the direction switch (direction) { case csDungeonCell.DirectionType.North: return(location.y > 0); case csDungeonCell.DirectionType.South: return(location.y < (Height - 1)); case csDungeonCell.DirectionType.West: return(location.x > 0); case csDungeonCell.DirectionType.East: return(location.x < (Width - 1)); default: return(false); } }
public void RemoveDeadEnds(csDungeon dungeon) { foreach (Vector2 deadEndLocation in dungeon.DeadEndCellLocations) { if (ShouldRemoveDeadend()) { Vector2 currentLocation = deadEndLocation; do { // Initialize the direction picker not to select the dead-end corridor direction csDirectionPicker directionPicker = new csDirectionPicker(); directionPicker.Constructor(dungeon[currentLocation].CalculateDeadEndCorridorDirection(), 100); csDungeonCell.DirectionType direction = directionPicker.GetNextDirection(); while (!dungeon.HasAdjacentCellInDirection(currentLocation, direction)) { if (directionPicker.HasNextDirection) { direction = directionPicker.GetNextDirection(); } else { throw new InvalidOperationException("This should not happen"); } } // Create a corridor in the selected direction currentLocation = dungeon.CreateCorridor(currentLocation, direction); } while (dungeon[currentLocation].IsDeadEnd); // Stop when you intersect an existing corridor. } } }
public bool AdjacentCellInDirectionIsCorridor(Vector2 location, csDungeonCell.DirectionType direction) { Vector2?target = GetTargetLocation(location, direction); if (target == null) { return(false); } switch (direction) { case csDungeonCell.DirectionType.North: return(this[target.Value].IsCorridor); case csDungeonCell.DirectionType.West: return(this[target.Value].IsCorridor); case csDungeonCell.DirectionType.South: return(this[target.Value].IsCorridor); case csDungeonCell.DirectionType.East: return(this[target.Value].IsCorridor); default: return(false); } }
protected Vector2?GetTargetLocation(Vector2 location, csDungeonCell.DirectionType direction) { if (!HasAdjacentCellInDirection(location, direction)) { return(null); } switch (direction) { case csDungeonCell.DirectionType.North: return(new Vector2(location.x, location.y - 1)); case csDungeonCell.DirectionType.West: return(new Vector2(location.x - 1, location.y)); case csDungeonCell.DirectionType.South: return(new Vector2(location.x, location.y + 1)); case csDungeonCell.DirectionType.East: return(new Vector2(location.x + 1, location.y)); default: throw new InvalidOperationException(); } }
public bool AdjacentCellInDirectionIsVisited(Vector2 location, csDungeonCell.DirectionType direction) { Vector2?target = GetTargetLocation(location, direction); if (target == null) { return(false); } switch (direction) { case csDungeonCell.DirectionType.North: return(this[target.Value].Visited); case csDungeonCell.DirectionType.West: return(this[target.Value].Visited); case csDungeonCell.DirectionType.South: return(this[target.Value].Visited); case csDungeonCell.DirectionType.East: return(this[target.Value].Visited); default: throw new InvalidOperationException(); } }
private Vector2 CreateSide(Vector2 location, csDungeonCell.DirectionType direction, csDungeonCell.SideType sideType) { Vector2?target = GetTargetLocation(location, direction); if (target == null) { throw new ArgumentException("There is no adjacent cell in the given direction", "location"); } switch (direction) { case csDungeonCell.DirectionType.North: this[location].NorthSide = sideType; this[target.Value].SouthSide = sideType; break; case csDungeonCell.DirectionType.South: this[location].SouthSide = sideType; this[target.Value].NorthSide = sideType; break; case csDungeonCell.DirectionType.West: this[location].WestSide = sideType; this[target.Value].EastSide = sideType; break; case csDungeonCell.DirectionType.East: this[location].EastSide = sideType; this[target.Value].WestSide = sideType; break; } return(target.Value); }
public Vector2 CreateCorridor(Vector2 location, csDungeonCell.DirectionType direction) { Vector2 targetLocation = CreateSide(location, direction, csDungeonCell.SideType.Empty); this[location].IsCorridor = true; // Set current location to corridor this[targetLocation].IsCorridor = true; // Set target location to corridor return(targetLocation); }
public Vector2 CreateDoor(Vector2 location, csDungeonCell.DirectionType direction) { return(CreateSide(location, direction, csDungeonCell.SideType.Door)); }
public void Constructor (csDungeonCell.DirectionType previousDirection, int changeDirectionModifier) { this.previousDirection = previousDirection; this.changeDirectionModifier = changeDirectionModifier; }