Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var map = new RoomSpace(new Point(0, 0), new Point(MaxWidth, MaxHeight));

            map.Split(11);
            map.GenerateRoom();

            var board = new int[MaxWidth, MaxHeight];

            map.Draw(board, 1, 3);
            PrintBoard(board);
        }
Exemplo n.º 2
0
        public void Split(int depth)
        {
            if (depth == 0)
            {
                return;
            }

            var splitOptions = SplitOptions();

            if (splitOptions == SplitDirection.None)
            {
                return;
            }

            Point startPoint;
            Point endPoint;

            CalcLimitPoints(out var minStartPoint, out var minEndPoint, MinPadding);

            switch (splitOptions)
            {
            case SplitDirection.Horizontal:
                CreateHorizontalLine(minStartPoint, minEndPoint, out startPoint, out endPoint);
                break;

            case SplitDirection.Vertical:
                CreateVerticalLine(minStartPoint, minEndPoint, out startPoint, out endPoint);
                break;

            case SplitDirection.Both:
                var randomSplitDirection = _random.Next(2);
                if (randomSplitDirection == 0)     // horizontal split
                {
                    CreateHorizontalLine(minStartPoint, minEndPoint, out startPoint, out endPoint);
                }
                else     // vertical split
                {
                    CreateVerticalLine(minStartPoint, minEndPoint, out startPoint, out endPoint);
                }
                break;

            case SplitDirection.None:
                throw new Exception("Logic exception, shouldn't get here");

            default:
                throw new ArgumentOutOfRangeException();
            }

            _line = new Line(startPoint, endPoint);

            var roomA = new RoomSpace(_leftUpperPoint, endPoint);
            var roomB = new RoomSpace(startPoint, _rightBottomPoint);

            _subRooms.Add(roomA);
            _subRooms.Add(roomB);

            --depth;
            foreach (var subRoom in _subRooms)
            {
                subRoom.Split(depth);
            }
        }