예제 #1
0
        public void CityLayer_ContainsExactlyTwoCities()
        {
            // :::: ARRANGE and ACT ::::
            var stubCities = StubWorld.NoCities;
            var stubCityFactory = StubFactories.SimpleCityFactory;
            var simpleFixedCityLayer = new SimpleFixedCityLayer(stubCities, stubCityFactory);

            // :::: ASSERT ::::
            simpleFixedCityLayer.Cities.Should().HaveCount(2);
        }
예제 #2
0
        public void CityLayer_ContainsARedCityAndABlueCity(ITile location, Player expectedOwner)
        {
            // :::: ARRANGE ::::
            var stubCities = StubWorld.NoCities;
            var stubCityFactory = StubFactories.SimpleCityFactory;
            var simpleFixedCityLayer = new SimpleFixedCityLayer(stubCities, stubCityFactory);

            // :::: ACT ::::
            var actualCity = simpleFixedCityLayer.Cities.Single(city => city.Location.Equals(location));

            // :::: ASSERT ::::
            actualCity.Owner.Should().Be(expectedOwner);
        }
예제 #3
0
        public IGame BuildGame()
        {
            // This composition of the game using poor man's DI does not support automatic registration.
            // To give a fairer view in the benchmark, it invokes the reflection used for automatic registration,
            // though it discards the results.
            var cityTypes = TypeConstraints.Cities;
            var cityFactoryTypes = TypeConstraints.CityFactories;
            var terrainTypes = TypeConstraints.Terrains;
            var terrainFactoryTypes = TypeConstraints.TerrainFactories;
            var unitTypes = TypeConstraints.Units;
            var unitFactoryTypes = TypeConstraints.UnitFactories;
            var productionProjectTypes = TypeConstraints.ProductionProjects;

            // :::: TURN-TAKING ::::
            var players = new[] { new Player("Red"), new Player("Blue") };
            var turnTaking = new RoundRobinTurns(players);

            // :::: UNIT COMBAT ::::
            var unitCombat = new AttackerIsAlwaysVictorious();

            // :::: WORLD MAP COLLECTIONS ::::
            var cities = new HashSet<ICity>(new CityEqualityComparer());
            var terrains = new HashSet<ITerrain>(new TerrainEqualityComparer());
            var units = new HashSet<IUnit>(new UnitEqualityComparer());

            // :::: CITIES ::::
            var cityFactory = new CityFactory(
                () => new FriendlyCityManagementOnly<City>(
                          new ProductionAccumulation<City>(
                              new FixedGeneratedProduction<City>(
                                  new NoCityGrowth<City>(new City())
                                  ), units, turnTaking
                              ), turnTaking
                          ));

            // :::: TERRAINS ::::
            var forestsFactory = new ForestsFactory(() => new Forests());
            var hillsFactory = new HillsFactory(() => new Hills());
            var mountainsFactory = new MountainsFactory(() => new Mountains());
            var oceansFactory = new OceansFactory(() => new Oceans());
            var plainsFactory = new PlainsFactory(() => new Plains());

            // :::: UNITS ::::
            var archerFactory = new ArcherFactory(
                () => new FriendlyUnitManagementOnly<Archer>(
                          new FortificationAction<Archer>(
                              new NoEntranceToImpassableTerrain<Archer>(
                                  new NoFriendlyUnitStacking<Archer>(
                                      new LimitedMoveRange<Archer>(
                                          new OneToOneCombatEngagement<Archer>(
                                              new CityConquest<Archer>(
                                                  new RestorationOfMoves<Archer>(
                                                      new MoveCosts<Archer>(
                                                          new Movability<Archer>(new Archer())
                                                          ), turnTaking
                                                      ), cities
                                                  ), units, unitCombat
                                              )
                                          ), units
                                      ), terrains
                                  )
                              ), turnTaking
                          ));

            var chariotFactory = new ChariotFactory(
                () => new FriendlyUnitManagementOnly<Chariot>(
                          new FortificationAction<Chariot>(
                              new NoEntranceToImpassableTerrain<Chariot>(
                                  new NoFriendlyUnitStacking<Chariot>(
                                      new LimitedMoveRange<Chariot>(
                                          new OneToOneCombatEngagement<Chariot>(
                                              new CityConquest<Chariot>(
                                                  new RestorationOfMoves<Chariot>(
                                                      new MoveCosts<Chariot>(
                                                          new Movability<Chariot>(new Chariot())
                                                          ), turnTaking
                                                      ), cities
                                                  ), units, unitCombat
                                              )
                                          ), units
                                      ), terrains
                                  )
                              ), turnTaking
                          ));

            var legionFactory = new LegionFactory(
                () => new FriendlyUnitManagementOnly<Legion>(
                          new NoEntranceToImpassableTerrain<Legion>(
                              new NoFriendlyUnitStacking<Legion>(
                                  new LimitedMoveRange<Legion>(
                                      new OneToOneCombatEngagement<Legion>(
                                          new CityConquest<Legion>(
                                              new RestorationOfMoves<Legion>(
                                                  new MoveCosts<Legion>(
                                                      new Movability<Legion>(new Legion())
                                                      ), turnTaking
                                                  ), cities
                                              ), units, unitCombat
                                          )
                                      ), units
                                  ), terrains
                              ), turnTaking
                          ));

            var settlerFactory = new SettlerFactory(
                () => new FriendlyUnitManagementOnly<Settler>(
                          new CityBuildingAction<Settler>(
                              new NoEntranceToImpassableTerrain<Settler>(
                                  new NoFriendlyUnitStacking<Settler>(
                                      new LimitedMoveRange<Settler>(
                                          new OneToOneCombatEngagement<Settler>(
                                              new RestorationOfMoves<Settler>(
                                                  new MoveCosts<Settler>(
                                                      new Movability<Settler>(new Settler())
                                                      ), turnTaking
                                                  ), units, unitCombat
                                              )
                                          ), units
                                      ), terrains
                                  ), units, cities, cityFactory
                              ), turnTaking
                          ));

            // :::: WORLD MAP LAYERS ::::
            var cityLayer = new SimpleFixedCityLayer(cities, cityFactory);

            var terrainLayer = new SimpleFixedTerrainLayer(terrains,
                                                           hillsFactory,
                                                           mountainsFactory,
                                                           oceansFactory,
                                                           plainsFactory);

            var unitLayer = new SimpleFixedUnitLayer(units, archerFactory, legionFactory, settlerFactory);

            // :::: WORLD AGE ::::
            var worldAge = new DeceleratingWorldAge(turnTaking);

            // :::: WINNER STRATEGY ::::
            var winnerStrategy = new CityConquerorWins(cities);

            // :::: PRODUCTION PROJECTS ::::
            var productionProjects = new Dictionary<string, IProductionProject>
            {
                ["Archer"] = new ArcherProject(archerFactory),
                ["Chariot"] = new ChariotProject(chariotFactory),
                ["Legion"] = new LegionProject(legionFactory),
                ["Settler"] = new SettlerProject(settlerFactory),
            };

            // :::: GAME ::::
            var game = new ExtenCivGame(cityLayer, terrainLayer, unitLayer,
                                        turnTaking, worldAge, winnerStrategy, productionProjects)
            {
                ContainerName = "Manual/SemiCiv"
            };

            return game;
        }