Ejemplo n.º 1
0
        internal RoomBlocks DecideLayout(int numBlocks)
        {
            numBlocks.ThrowIfBelow(2, nameof(numBlocks));

            var blocks = new RoomBlocks(numBlocks);

            var point = RandomCoordinates(blocks);

            blocks[point] = true;
            --numBlocks;

            while (numBlocks > 0)
            {
                if (!blocks[point] && blocks.IsTouchingAnyBlock(point))
                {
                    blocks[point] = true;
                    if (--numBlocks == 0)
                    {
                        continue;
                    }
                }

                if (blocks.IsCornered(point) || !blocks.IsTouchingAnyBlock(point))
                {
                    point = RandomCoordinates(blocks);
                }
                else
                {
                    point = RandomWalkCoordinates(blocks, point);
                }
            }

            return(blocks);
        }
Ejemplo n.º 2
0
        internal Room(RoomBlocks blocks, DispatchRegistry registry, IRandomNumberGenerator randomNumbers, int tilesPerBlock)
            : base(Coordinate.NotSet, registry)
        {
            blocks.ThrowIfNull(nameof(blocks));
            randomNumbers.ThrowIfNull(nameof(randomNumbers));

            _randomNumbers = randomNumbers;

            Tiles = new RoomTiles(blocks.RowUpperBound, blocks.ColumnUpperBound, tilesPerBlock, Registry, _randomNumbers);
        }
Ejemplo n.º 3
0
        private Coordinate RandomCoordinates(RoomBlocks blocks)
        {
            Coordinate point;

            do
            {
                point = new Coordinate(
                    _randomNumberGenerator.Dice(blocks.RowUpperBound),
                    _randomNumberGenerator.Dice(blocks.ColumnUpperBound)
                    );
            } while (!blocks.IsInside(point));

            return(point);
        }
Ejemplo n.º 4
0
        private Coordinate RandomWalkCoordinates(RoomBlocks blocks, Coordinate point)
        {
            Coordinate nextPoint;

            Compass4Points randomDirection;

            do
            {
                randomDirection = _randomNumberGenerator.Enum <Compass4Points>();
                nextPoint       = point.Move(randomDirection);
            } while (!blocks.IsInside(nextPoint));

            _logger.Debug($"From Point [{point}] go [{randomDirection.ToString()}] to [{nextPoint}]");

            return(nextPoint);
        }
Ejemplo n.º 5
0
        internal Room PopulateWithSpace(RoomBlocks blocks)
        {
            var emptyTiles = new List <(string Name, Coordinate Coordinates)>();

            for (var blockRow = 0; blockRow <= blocks.RowUpperBound; blockRow++)
            {
                for (var blockCol = 0; blockCol <= blocks.ColumnUpperBound; blockCol++)
                {
                    var coordinate = new Coordinate(blockRow, blockCol);
                    if (blocks[coordinate])
                    {
                        var blockOfEmptyTiles = Tiles.PopulateBlock(blockRow, blockCol);
                        emptyTiles.AddRange(blockOfEmptyTiles);
                    }
                }
            }

            return(Clone(emptyTiles.ToTilesState()));
        }