示例#1
0
        public void CityAt_ReturnsNull_WhenThereIsNoCityOnTheTile()
        {
            // :::: ARRANGE ::::
            var game = new ExtenCivGame(DummyCityLayer, DummyTerrainLayer, DummyUnitLayer,
                                        DummyTurnTaking, DummyWorldAge, DummyWinnerStrategy,
                                        DummyProjects);

            // :::: ACT ::::
            var actualCityViewModel = game.CityAt(DummyTile);

            // :::: ASSERT ::::
            actualCityViewModel.Should().BeNull();
        }
示例#2
0
        public void TerrainAt_ReturnsTheTerrainOnTheTile(ITerrain terrain, string expectedTerrainType)
        {
            // :::: ARRANGE ::::
            var stubTerrainLayer = StubWorld.TerrainLayer(new[] { terrain });
            var game = new ExtenCivGame(DummyCityLayer, stubTerrainLayer, DummyUnitLayer,
                                        DummyTurnTaking, DummyWorldAge, DummyWinnerStrategy,
                                        DummyProjects);

            // :::: ACT ::::
            var location = terrain.Location;
            var actualTerrainViewModel = game.TerrainAt(location);

            // :::: ASSERT ::::
            actualTerrainViewModel.Type.Should().Be(expectedTerrainType);
        }
示例#3
0
        public void CityAt_ReturnsTheCityOnTheTile(ICity city)
        {
            // :::: ARRANGE ::::
            var stubCityLayer = StubWorld.CityLayer(new[] { city });
            var game = new ExtenCivGame(stubCityLayer, DummyTerrainLayer, DummyUnitLayer,
                                        DummyTurnTaking, DummyWorldAge, DummyWinnerStrategy,
                                        DummyProjects);

            // :::: ACT ::::
            var location = city.Location;
            var actualCityViewModel = game.CityAt(location);

            // :::: ASSERT ::::
            actualCityViewModel.Owner.Should().Be(city.Owner);
            actualCityViewModel.Population.Should().Be(city.Population);
        }
示例#4
0
        public void ChangeCityProductionProjectAt_InvokesSetProductionProjectOnTheCity(ITile tile, string project)
        {
            // :::: ARRANGE ::::
            var dummyProject = A.Fake<IProductionProject>();
            var stubProjects = new Dictionary<string, IProductionProject> { [project] = dummyProject };
            var spyCity = A.Fake<ICity>();
            var stubCityLayer = StubWorld.CityLayer(new[] { spyCity });
            var game = new ExtenCivGame(stubCityLayer, DummyTerrainLayer, DummyUnitLayer,
                                        DummyTurnTaking, DummyWorldAge, DummyWinnerStrategy,
                                        stubProjects);

            A.CallTo(() => spyCity.Location).Returns(tile);

            // :::: ACT ::::
            game.ChangeCityProductionProjectAt(tile, project);

            // :::: ASSERT ::::
            // The setter of ProductionProject has been invoked.
            A.CallTo(spyCity)
             .Where(x => x.Method.Name == $"set_{nameof(spyCity.ProductionProject)}"
                         && ReferenceEquals(x.Arguments[0], dummyProject))
             .MustHaveHappened();
        }
示例#5
0
        public void PerformUnitActionAt_InvokesPerformActionOnTheUnit(ITile tile)
        {
            // :::: ARRANGE ::::
            var spyUnit = A.Fake<IUnit>();
            var stubUnitLayer = StubWorld.UnitLayer(new[] { spyUnit });
            var game = new ExtenCivGame(DummyCityLayer, DummyTerrainLayer, stubUnitLayer,
                                        DummyTurnTaking, DummyWorldAge, DummyWinnerStrategy,
                                        DummyProjects);

            A.CallTo(() => spyUnit.Location).Returns(tile);

            // :::: ACT ::::
            game.PerformUnitActionAt(tile);

            // :::: ASSERT ::::
            A.CallTo(() => spyUnit.PerformAction()).MustHaveHappened();
        }
示例#6
0
        public void MoveUnit_InvokesMoveToOnTheUnit(ITile origin, ITile destination)
        {
            // :::: ARRANGE ::::
            var spyUnit = A.Fake<IUnit>();
            var stubUnitLayer = StubWorld.UnitLayer(new[] { spyUnit });
            var game = new ExtenCivGame(DummyCityLayer, DummyTerrainLayer, stubUnitLayer,
                                        DummyTurnTaking, DummyWorldAge, DummyWinnerStrategy,
                                        DummyProjects);

            A.CallTo(() => spyUnit.Location).Returns(origin);

            // :::: ACT ::::
            game.MoveUnit(origin, destination);

            // :::: ASSERT ::::
            A.CallTo(() => spyUnit.MoveTo(destination)).MustHaveHappened();
        }
示例#7
0
        public void EndTurn_InvokesAdvanceToNextPlayerOnTheTurnTaking()
        {
            // :::: ARRANGE ::::
            var spyTurnTaking = A.Fake<ITurnTaking>();
            var game = new ExtenCivGame(DummyCityLayer, DummyTerrainLayer, DummyUnitLayer,
                                        spyTurnTaking, DummyWorldAge, DummyWinnerStrategy,
                                        DummyProjects);

            // :::: ACT ::::
            game.EndTurn();

            // :::: ASSERT ::::
            A.CallTo(() => spyTurnTaking.AdvanceToNextPlayer()).MustHaveHappened();
        }
示例#8
0
        public void Round_ReturnsTheCurrentRoundNumber(int round)
        {
            // :::: ARRANGE ::::
            var stubTurnTaking = A.Fake<ITurnTaking>();
            var game = new ExtenCivGame(DummyCityLayer, DummyTerrainLayer, DummyUnitLayer,
                                        stubTurnTaking, DummyWorldAge, DummyWinnerStrategy,
                                        DummyProjects);

            A.CallTo(() => stubTurnTaking.CurrentRound).Returns(round);

            // :::: ACT ::::
            var actualRound = game.Round;

            // :::: ASSERT ::::
            actualRound.Should().Be(round);
        }
示例#9
0
        public void WorldAge_ReturnsTheWorldAge(int worldAge)
        {
            // :::: ARRANGE ::::
            var stubWorldAge = A.Fake<IWorldAge>();
            var game = new ExtenCivGame(DummyCityLayer, DummyTerrainLayer, DummyUnitLayer,
                                        DummyTurnTaking, stubWorldAge, DummyWinnerStrategy,
                                        DummyProjects);

            A.CallTo(() => stubWorldAge.CurrentWorldAge).Returns(worldAge);

            // :::: ACT ::::
            var actualWorldAge = game.WorldAge;

            // :::: ASSERT ::::
            actualWorldAge.Should().Be(worldAge);
        }
示例#10
0
        public void Winner_ReturnsTheWinner(Player winner)
        {
            // :::: ARRANGE ::::
            var stubWinnerStrategy = A.Fake<IWinnerStrategy>();
            var game = new ExtenCivGame(DummyCityLayer, DummyTerrainLayer, DummyUnitLayer,
                                        DummyTurnTaking, DummyWorldAge, stubWinnerStrategy,
                                        DummyProjects);

            A.CallTo(() => stubWinnerStrategy.Winner).Returns(winner);

            // :::: ACT ::::
            var actualWinner = game.Winner;

            // :::: ASSERT ::::
            actualWinner.Should().Be(winner);
        }
示例#11
0
        public void CurrentPlayer_ReturnsTheCurrentPlayerInTurn(Player player)
        {
            // :::: ARRANGE ::::
            var stubTurnTaking = A.Fake<ITurnTaking>();
            var game = new ExtenCivGame(DummyCityLayer, DummyTerrainLayer, DummyUnitLayer,
                                        stubTurnTaking, DummyWorldAge, DummyWinnerStrategy,
                                        DummyProjects);

            A.CallTo(() => stubTurnTaking.CurrentPlayer).Returns(player);

            // :::: ACT ::::
            var actualCurrentPlayer = game.CurrentPlayer;

            // :::: ASSERT ::::
            actualCurrentPlayer.Should().Be(player);
        }
示例#12
0
        public void UnitAt_ReturnsTheUnitOnTheTile(IUnit unit, string expectedUnitType)
        {
            // :::: ARRANGE ::::
            var stubUnitLayer = StubWorld.UnitLayer(new[] { unit });
            var game = new ExtenCivGame(DummyCityLayer, DummyTerrainLayer, stubUnitLayer,
                                        DummyTurnTaking, DummyWorldAge, DummyWinnerStrategy,
                                        DummyProjects);

            // :::: ACT ::::
            var location = unit.Location;
            var actualUnitViewModel = game.UnitAt(location);

            // :::: ASSERT ::::
            actualUnitViewModel.Type.Should().Be(expectedUnitType);
            actualUnitViewModel.Owner.Should().Be(unit.Owner);
            actualUnitViewModel.RemainingMovement.Should().Be(unit.RemainingMoves);
        }
示例#13
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;
        }