Ejemplo n.º 1
0
 //attempt to remove some dead ends
 private void RemoveDeadEnds(int removalModifier)
 {
     foreach (Point p in DeadEndLocations())
     {
         if (ShouldRemoveDeadEnd(removalModifier))
         {
             Point current = p;
             do
             {
                 DirectionPicker dirPicker = new DirectionPicker(visited[current.X, current.Y].DeadEndDirection, 100);
                 Direction direction = dirPicker.GetNextDirection();
                 while (!HasAdjacentCellInDirection(current, direction))
                 {
                     if (dirPicker.HasNextDirection)
                     {
                         direction = dirPicker.GetNextDirection();
                     }
                     else
                     {
                         throw new Exception();
                     }
                 }
                 current = CreateCorridor(current, direction);
             } while (visited[current.X, current.Y].IsDeadEnd);
         }
     }
 }
Ejemplo n.º 2
0
        public void Generate()
        {
            visited = new Cell[Width, Height];

            TCODRandom random = TCODRandom.getInstance();

            //initialise the array
            for (ushort x = 0; x < Width; ++x)
            {
                for (ushort y = 0; y < Height; ++y)
                    visited[x, y] = new Cell();
            }

            //pick a random point, visit it
            Point currentPoint = PickRandomPointToVisit();
            Direction previous = Direction.North;

            //visit all the others
            while (visitedIndices.Count != Width * Height)
            {
                //pick a direction
                DirectionPicker directionPicker = new DirectionPicker(previous, 30);
                Direction dir = directionPicker.GetNextDirection();

                //whilst the direction is invalid, generate a new one
                while (!HasAdjacentCellInDirection(currentPoint, dir) || IsAdjacentCellVisited(currentPoint, dir))
                {
                    if (directionPicker.HasNextDirection)

                        dir = directionPicker.GetNextDirection();
                    else
                    {
                        //if we can't generate a new one, then pick a new point
                        currentPoint = DarkRL.SelectRandomFromList(visitedIndices);
                        directionPicker = new DirectionPicker(previous, 30);
                        dir = directionPicker.GetNextDirection();
                    }
                }

                //create a corridor, mark it up
                currentPoint = CreateCorridor(currentPoint, dir);
                MarkVisited(currentPoint);
                previous = dir;
            }

            //remove some of the corridors
            Sparsify(65);
            RemoveDeadEnds(100);

            PlaceRooms(Width * Height / 700, 7, 20, 7, 20);

            //and cleanup
            Cleanup(1, 60, 12);
            Cleanup(1, 50, 5);
        }