Ejemplo n.º 1
0
        public void LaunchGame_GameLaunchedAfterJoining_InitialBoardPassedBack()
        {
            var mockDice = new MockDiceCreator()
                           .AddExplicitDiceRollSequence(new uint[] { 12, 10, 8, 2 })
                           .Create();

            var player    = new MockPlayer(PlayerName);
            var opponents = new[]
            {
                new MockComputerPlayer(FirstOpponentName),
                new MockComputerPlayer(SecondOpponentName),
                new MockComputerPlayer(ThirdOpponentName)
            };

            var mockPlayerFactory = LocalGameControllerTestCreator.CreateMockPlayerPool(player, opponents);

            var localGameController = new LocalGameControllerCreator().ChangeDice(mockDice).ChangePlayerPool(mockPlayerFactory).Create();

            GameBoardSetup gameBoardData = null;

            localGameController.InitialBoardSetupEvent = (GameBoardSetup g) => { gameBoardData = g; };

            localGameController.JoinGame();
            localGameController.LaunchGame();

            gameBoardData.ShouldNotBeNull();
        }
Ejemplo n.º 2
0
        public void PlayerSelectsLocationTooCloseToComputerPlayerDuringFirstSetupRound_MeaningfulErrorIsReceived()
        {
            var mockDice = new MockDiceCreator()
                           .AddExplicitDiceRollSequence(new uint[] { 10, 12, 8, 6 })
                           .Create();

            MockPlayer         player;
            MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent;

            this.CreateDefaultPlayerInstances(out player, out firstOpponent, out secondOpponent, out thirdOpponent);

            var localGameController = this.CreateLocalGameController(mockDice, player, firstOpponent, secondOpponent, thirdOpponent);

            ErrorDetails exception = null;

            localGameController.ErrorRaisedEvent = (ErrorDetails e) => { exception = e; };
            localGameController.JoinGame();
            localGameController.LaunchGame();
            localGameController.StartGameSetup();

            localGameController.ContinueGameSetup(19u, 1u);

            exception.ShouldNotBeNull();
            exception.Message.ShouldBe("Cannot build settlement. Too close to player '" + FirstOpponentName + "' at location " + FirstSettlementOneLocation + ".");
        }
Ejemplo n.º 3
0
        public void Create_DuplicateRollsAreIgnored_ReturnsPlayersInDescendingOrder(UInt32 firstRoll, UInt32 secondRoll, UInt32 thirdRoll, UInt32 fourthRoll, Int32 first, Int32 second, Int32 third)
        {
            var players = new Player[] { new Player(), new Player(), new Player() };

            var mockDice = new MockDiceCreator()
                           .AddExplicitDiceRollSequence(new uint[] { firstRoll, secondRoll, thirdRoll, fourthRoll })
                           .Create();

            var setupOrder = PlayerTurnOrderCreator.Create(players, mockDice);

            setupOrder.ShouldBe(new IPlayer[] { players[first], players[second], players[third] });
        }
Ejemplo n.º 4
0
        private LocalGameController CreateLocalGameControllerWithMainPlayerGoingFirstInSetup()
        {
            var mockDice = new MockDiceCreator()
                           .AddExplicitDiceRollSequence(new uint[] { 12, 10, 8, 6 })
                           .Create();

            MockPlayer         player;
            MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent;

            this.CreateDefaultPlayerInstances(out player, out firstOpponent, out secondOpponent, out thirdOpponent);

            return(this.CreateLocalGameController(mockDice, player, firstOpponent, secondOpponent, thirdOpponent));
        }
Ejemplo n.º 5
0
        public void Create_DifferentRolls_ReturnsPlayersInDescendingOrder(UInt32 firstRoll, UInt32 secondRoll, UInt32 thirdRoll, UInt32 fourthRoll, Int32 first, Int32 second, Int32 third, Int32 fourth)
        {
            var player1 = new Player();
            var player2 = new Player();
            var player3 = new Player();
            var player4 = new Player();

            var players  = new IPlayer[] { player1, player2, player3, player4 };
            var mockDice = new MockDiceCreator()
                           .AddExplicitDiceRollSequence(new uint[] { firstRoll, secondRoll, thirdRoll, fourthRoll })
                           .Create();
            var setupOrder = PlayerTurnOrderCreator.Create(players, mockDice);

            setupOrder.ShouldBe(new IPlayer[] { players[first], players[second], players[third], players[fourth] });
        }
Ejemplo n.º 6
0
        public void CompleteSetupWithPlayerInSecondSlot_ExpectedPlacementsAreReturned()
        {
            var gameSetupOrder = new[] { 10u, 12u, 8u, 6u };
            var mockDice       = new MockDiceCreator()
                                 .AddExplicitDiceRollSequence(gameSetupOrder)
                                 .Create();

            var testInstances       = LocalGameControllerTestCreator.CreateTestInstances(mockDice);
            var firstOpponent       = testInstances.FirstOpponent;
            var secondOpponent      = testInstances.SecondOpponent;
            var thirdOpponent       = testInstances.ThirdOpponent;
            var localGameController = testInstances.LocalGameController;

            var gameEvents = new List <GameEvent>();

            localGameController.GameEvents = (List <GameEvent> e) => { gameEvents = e; };

            localGameController.JoinGame();
            localGameController.LaunchGame();

            localGameController.StartGameSetup();
            gameEvents.Count.ShouldBe(1);
            gameEvents[0].ShouldBe(new SetupInfrastructurePlacedEvent(firstOpponent.Id, FirstSettlementOneLocation, FirstRoadOneEnd));

            gameEvents.Clear();
            localGameController.ContinueGameSetup(MainSettlementOneLocation, MainRoadOneEnd);

            gameEvents.Count.ShouldBe(6);
            gameEvents[0].ShouldBe(new SetupInfrastructurePlacedEvent(secondOpponent.Id, SecondSettlementOneLocation, SecondRoadOneEnd));
            gameEvents[1].ShouldBe(new SetupInfrastructurePlacedEvent(thirdOpponent.Id, ThirdSettlementOneLocation, ThirdRoadOneEnd));
            gameEvents[2].ShouldBe(new SetupInfrastructurePlacedEvent(thirdOpponent.Id, ThirdSettlementTwoLocation, ThirdRoadTwoEnd));
            //gameEvents[3].ShouldBe(new ResourcesCollectedEvent(thirdOpponent.Id, new[] { new ResourceCollection(ThirdSettlementTwoLocation, new ResourceClutch(0, 1, 1, 0, 1)) }));
            gameEvents[4].ShouldBe(new SetupInfrastructurePlacedEvent(secondOpponent.Id, SecondSettlementTwoLocation, SecondRoadTwoEnd));
            //gameEvents[5].ShouldBe(new ResourcesCollectedEvent(secondOpponent.Id, new[] { new ResourceCollection(SecondSettlementTwoLocation, new ResourceClutch(0, 0, 1, 1, 1)) }));

            gameEvents.Clear();
            localGameController.CompleteGameSetup(MainSettlementTwoLocation, MainRoadTwoEnd);

            gameEvents.Count.ShouldBe(3);
            //gameEvents[0].ShouldBe(new ResourcesCollectedEvent(testInstances.MainPlayer.Id, new[] { new ResourceCollection(MainSettlementTwoLocation, new ResourceClutch(1, 1, 0, 0, 1)) }));
            gameEvents[1].ShouldBe(new SetupInfrastructurePlacedEvent(firstOpponent.Id, FirstSettlementTwoLocation, FirstRoadTwoEnd));
            //gameEvents[2].ShouldBe(new ResourcesCollectedEvent(firstOpponent.Id, new[] { new ResourceCollection(FirstSettlementTwoLocation, new ResourceClutch(0, 1, 1, 0, 1)) }));
        }
Ejemplo n.º 7
0
        public void PlayerSelectsSameLocationAsComputerPlayerDuringFirstSetupRound_MeaningfulErrorIsReceived()
        {
            var mockDice = new MockDiceCreator()
                           .AddExplicitDiceRollSequence(new uint[] { 10, 12, 8, 6 })
                           .Create();

            var localGameController = LocalGameControllerTestCreator.CreateTestInstances(mockDice, null, null, null)
                                      .LocalGameController;

            ErrorDetails exception = null;

            localGameController.ErrorRaisedEvent = (ErrorDetails e) => { exception = e; };

            localGameController.JoinGame();
            localGameController.LaunchGame();
            localGameController.StartGameSetup();

            localGameController.ContinueGameSetup(FirstSettlementOneLocation, 1u);

            exception.ShouldNotBeNull();
            exception.Message.ShouldBe("Cannot build settlement. Location " + FirstSettlementOneLocation + " already settled by player '" + FirstOpponentName + "'.");
        }