Exemple #1
0
        public Point GetRandomNeighbour(Point roomToConnect)
        {
            Direction[] allDirections = (Direction[])Enum.GetValues(typeof(Direction));
            Direction   direction     = Chance.RandomElement(allDirections);

            return(roomToConnect.Add(direction));
        }
Exemple #2
0
        private string GetRoomDescription()
        {
            if (streetNames.Count == 0)
            {
                return("A busy street in London.");
            }
            var result = Chance.RandomElement(streetNames);

            streetNames.Remove(result);
            return(result.Substring(0, result.Length - 1));
        }
Exemple #3
0
 /// <summary>
 /// Create rooms next to the current one as long as there are still null neighbours
 /// </summary>
 /// <param name="fromPoint"></param>
 private void CreateNeighbour(Point fromPoint)
 {
     while (true)
     {
         List <Point> options = ListEmptyNeighbours(fromPoint);
         if (options.Count == 0)
         {
             return;
         }
         Point destPoint = Chance.RandomElement(options);
         Rooms[destPoint.X, destPoint.Y] = new Room(GetRoomDescription(), destPoint);
         Connect(fromPoint, destPoint);
         CreateNeighbour(destPoint); //recursive step
     }
 }
Exemple #4
0
        public Room GetRandomOtherRoom(Room currentRoom)
        {
            List <Room> otherRooms = new List <Room>();

            foreach (Room room in this)
            {
                if (room.LocationOfRoom != currentRoom.LocationOfRoom)
                {
                    otherRooms.Add(room);
                }
            }
            if (otherRooms.Count == 0)
            {
                return(null);
            }
            return(Chance.RandomElement(otherRooms));
        }