public void Fill(EmptyAreaGroup emptyAreaGroup)
        {
            var buildingTypesBySize = BuildingTypesProvider.GetGroupedBySize();

            for (var index = 0; index < buildingTypesBySize.Count; ++index)
            {
                var buildingTypesOfEqualSize = buildingTypesBySize[index];
                var tileAnglesCombinations   = new TileAnglesCombinations(emptyAreaGroup.Tiles);
                while (tileAnglesCombinations.Any())
                {
                    var buildingLocation  = _randomBuildingLocationGenerator.Generate(tileAnglesCombinations, buildingTypesOfEqualSize);
                    var building          = buildingLocation.Instantiate();
                    var placingPointOnMap = _map.GetLocationOf(buildingLocation.Tile);

                    tileAnglesCombinations.RemoveAngleForTile(buildingLocation.Angle, buildingLocation.Tile);

                    _buildingOnMapIfPossibleLocator.TryLocate(building, placingPointOnMap);
                    if (ShallFinishWithCurrentBuildingType(emptyAreaGroup, index))
                    {
                        break;
                    }
                }
            }

            var mapParameters = new MapFillingParametersCalculator().Calculate(_map);
        }
Beispiel #2
0
        public void SingleEmptyGroup_ShallBeSurroundedWithStreetTiles()
        {
            var map        = new CityBuilder.MapModel.Map(5, 7);
            var emptyGroup = new EmptyAreaGroup
            {
                Tiles = new List <ITile>
                {
                    map[1, 1],
                    map[1, 2],
                    map[2, 1],
                    map[2, 2],
                }
            };

            foreach (var tile in emptyGroup.Tiles)
            {
                tile.TileState = TileState.Empty;
            }

            _cut.AppendStreets(map, new List <EmptyAreaGroup> {
                emptyGroup
            });

            Assert.AreEqual(4, emptyGroup.Tiles.Count(a => a.TileState == TileState.Empty));
            Assert.AreEqual(12, map.AllTiles.Count(a => a.TileState == TileState.Street));
        }
Beispiel #3
0
        public void IfTwoGroupsTouchByCorners_OneCornerShallBeRemoved_ToCreatePassage()
        {
            var map             = new CityBuilder.MapModel.Map(6, 6);
            var firstEmptyGroup = new EmptyAreaGroup
            {
                Tiles = new List <ITile>
                {
                    map[1, 1],
                    map[1, 2],
                    map[2, 1],
                    map[2, 2],
                }
            };

            foreach (var tile in firstEmptyGroup.Tiles)
            {
                tile.TileState = TileState.Empty;
            }

            var secondEmptyGroup = new EmptyAreaGroup
            {
                Tiles = new List <ITile>
                {
                    map[3, 3],
                    map[3, 4],
                    map[4, 3],
                    map[4, 4],
                }
            };

            foreach (var tile in secondEmptyGroup.Tiles)
            {
                tile.TileState = TileState.Empty;
            }

            _cut.AppendStreets(map, new List <EmptyAreaGroup> {
                firstEmptyGroup, secondEmptyGroup
            });

            Assert.AreEqual(4, firstEmptyGroup.Tiles.Count(a => a.TileState == TileState.Empty));
            Assert.AreEqual(3, secondEmptyGroup.Tiles.Count(a => a.TileState == TileState.Empty));

            Assert.AreEqual(21, map.AllTiles.Count(a => a.TileState == TileState.Street));
        }
 private bool ShallFinishWithCurrentBuildingType(EmptyAreaGroup emptyAreaGroup, int index)
 {
     return(_mapFillingParametersCalculator.GetMapFillingFactor(emptyAreaGroup.Tiles) > (decimal)(index + 1) / 5);
 }