コード例 #1
0
        private void BuildCorridor(IMap map, MapCell currentCell)
        {
            MapCell nextCell;
            var direction = Dir.Zero;

            bool success;
            do
            {
                _directionPicker.LastDirection = direction;
                _directionPicker.ResetDirections();
                var emptySide = currentCell.Sides
                    .Single(s => s.Value != Side.Wall)
                    .Key;
                success = false;
                do
                {
                    direction = _directionPicker.NextDirectionExcept(emptySide);
                    success = map.TryGetAdjacentCell(currentCell, direction, out nextCell);

                    if (success)
                    {
                        map.CreateCorridorSide(currentCell, nextCell, direction, Side.Empty);
                    }
                } while (_directionPicker.HasDirections && !success);

                if (!success)
                {
                    return;
                }
            } while (currentCell.IsDeadEnd);
        }
コード例 #2
0
        private bool TryPickRandomUnvisitedAdjacentCell(
            IMap map, MapCell currentCell, out MapCell nextCell, out Dir direction)
        {
            var success = false;
            do
            {
                direction = _directionPicker.NextDirection();
                success = map.TryGetAdjacentCell(currentCell, direction, out nextCell)
                    && !nextCell.IsVisited;
            }
            while (_directionPicker.HasDirections && !success);

            return success;
        }
コード例 #3
0
 private static bool HasAdjacentCorridor(
     IMap map, MapCell currentCell, Dir dir)
 {
     MapCell adjacentCell;
     return map.TryGetAdjacentCell(currentCell, dir, out adjacentCell)
         && adjacentCell.Sides[dir] != Side.Wall;
 }