Esempio n. 1
0
        public SimpleFixedCityLayer(ISet<ICity> cities, ICityFactory<City> cityFactory)
        {
            Cities = cities;

            Cities.Add(cityFactory.Create(RedCityTile, Red));
            Cities.Add(cityFactory.Create(BlueCityTile, Blue));
        }
        public async Task <CityDTO> AddAsync(string name)
        {
            var doesCityExist = await context.Cities.AnyAsync(c => c.Name.ToLower() == name.ToLower());

            if (doesCityExist)
            {
                throw new ArgumentException(OutputConstants.CityAlreadyExists);
            }

            var city = cityFactory.Create(name);

            context.Cities.Add(city);
            await context.SaveChangesAsync();

            var cityDTO = await context.Cities
                          .Where(c => c.Name == name && c.IsDeleted == false)
                          .Select(c => new CityDTO
            {
                Id   = city.Id,
                Name = city.Name
            })
                          .FirstAsync();

            return(cityDTO);
        }
Esempio n. 3
0
        public void Create_ReturnsAUnitWithALocationAndAnOwner(ITile location, Player owner, ICityFactory<City> factory)
        {
            // :::: ACT ::::
            var city = factory.Create(location, owner);

            // :::: ASSERT ::::
            city.Location.Should().Be(location);
            city.Owner.Should().Be(owner);
        }
Esempio n. 4
0
        public async Task <IEnumerable <ICity> > GetAllAsync()
        {
            using (var databaseContext = _databaseContextFactory.Create())
            {
                var cityEntities = await databaseContext
                                   .City
                                   .ToListAsync();

                var cities = cityEntities
                             .Select(entity => _cityFactory.Create(entity.Name, entity.Code))
                             .ToArray();

                return(cities);
            }
        }
Esempio n. 5
0
        public void HandleCommandOnUnit(AbilityCommandRequest command, IUnit unit)
        {
            if (CanHandleCommandOnUnit(command, unit))
            {
                var unitOwner     = UnitOwnershipCanon.GetOwnerOfPossession(unit);
                var citiesOfOwner = CityPossessionCanon.GetPossessionsOfOwner(unitOwner);

                var cityName = unitOwner.Template.GetNextName(citiesOfOwner);

                CityFactory.Create(UnitPositionCanon.GetOwnerOfPossession(unit), unitOwner, cityName);
            }
            else
            {
                throw new InvalidOperationException("Cannot handle command");
            }
        }
        public void DecomposeCities(SerializableMapData mapData)
        {
            foreach (var cityData in mapData.Cities)
            {
                var owner    = CivilizationFactory.AllCivilizations.Where(civ => civ.Template.Name.Equals(cityData.Owner)).FirstOrDefault();
                var location = Grid.GetCellAtCoordinates(cityData.Location);

                var newCity = CityFactory.Create(location, owner, cityData.Name);

                newCity.Population       = cityData.Population;
                newCity.FoodStockpile    = cityData.FoodStockpile;
                newCity.CultureStockpile = cityData.CultureStockpile;
                newCity.YieldFocus       = cityData.YieldFocus;
                newCity.CombatFacade.CurrentHitpoints = cityData.Hitpoints;
                newCity.CombatFacade.CurrentMovement  = cityData.CurrentMovement;

                DecomposeActiveProject(cityData, newCity);
                DecomposeAppliedTemplates(cityData, newCity);
            }
        }
        private void OnCellClicked(Tuple <IHexCell, PointerEventData> data)
        {
            var cell = data.Item1;

            if (IsAdding)
            {
                if (CityValidityLogic.IsCellValidForCity(cell))
                {
                    var citiesOfCiv = CityPossessionCanon.GetPossessionsOfOwner(ActiveCivilization);

                    CityFactory.Create(cell, ActiveCivilization, ActiveCivilization.Template.GetNextName(citiesOfCiv));
                }
            }
            else
            {
                var cityAtLocation = CityLocationCanon.GetPossessionsOfOwner(cell).FirstOrDefault();
                if (cityAtLocation != null)
                {
                    cityAtLocation.Destroy();
                }
            }
        }
 public ICity Translate(IWeatherForecast weatherForecast)
 {
     return(_cityFactory.Create(weatherForecast.CityName, weatherForecast.Code));
 }