Esempio n. 1
0
        public void Scenario_OpponentUsesMonopolyCardAndGetsResourcesFromPlayer()
        {
            // Arrange
            var monopolyCard        = new MonopolyDevelopmentCard();
            var testInstances       = this.TestSetup(new MockGameBoardWithNoResourcesCollected(), monopolyCard);
            var localGameController = testInstances.LocalGameController;

            testInstances.Dice.AddSequence(new uint[] { 8, 8, 8, 8 });

            var player         = testInstances.MainPlayer;
            var firstOpponent  = testInstances.FirstOpponent;
            var secondOpponent = testInstances.SecondOpponent;
            var thirdOpponent  = testInstances.ThirdOpponent;

            testInstances.Dice.AddSequence(new uint[] { 3, 3, 8, 8 });  // Only second opp will collect resources (2 Ore)

            player.AddResources(ResourceClutch.OneBrick);
            firstOpponent.AddResources(ResourceClutch.DevelopmentCard);
            firstOpponent.AddBuyDevelopmentCardChoice(1).EndTurn()
            .AddPlaceMonopolyCardInstruction(new PlayMonopolyCardInstruction {
                ResourceType = ResourceTypes.Brick
            }).EndTurn();

            secondOpponent.AddResources(new ResourceClutch(2, 1, 1, 1, 1));

            var       turn      = 0;
            GameToken turnToken = null;

            localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; turn++; };

            var gameEvents = new List <List <GameEvent> >();

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

            localGameController.StartGamePlay();
            localGameController.EndTurn(turnToken); // Opponent buys development cards
            localGameController.EndTurn(turnToken); // Opponent plays monopoly cards

            // Assert
            var expectedBuyDevelopmentCardEvent = new BuyDevelopmentCardEvent(firstOpponent.Id);

            var expectedResourceTransactionList = new ResourceTransactionList();

            expectedResourceTransactionList.Add(new ResourceTransaction(firstOpponent.Id, player.Id, ResourceClutch.OneBrick));
            expectedResourceTransactionList.Add(new ResourceTransaction(firstOpponent.Id, secondOpponent.Id, ResourceClutch.OneBrick * 2));
            var expectedPlayMonopolyCardEvent = new PlayMonopolyCardEvent(firstOpponent.Id, expectedResourceTransactionList);

            gameEvents.Count.ShouldBe(15);
            gameEvents[2].Count.ShouldBe(2);
            gameEvents[2][1].ShouldBe(expectedBuyDevelopmentCardEvent);
            gameEvents[9].Count.ShouldBe(2);
            gameEvents[9][1].ShouldBe(expectedPlayMonopolyCardEvent);

            player.Resources.Count.ShouldBe(0);
            firstOpponent.Resources.Count.ShouldBe(3);
            firstOpponent.Resources.BrickCount.ShouldBe(firstOpponent.Resources.Count);
            secondOpponent.Resources.Count.ShouldBe(4);
            secondOpponent.Resources.BrickCount.ShouldBe(0);
            thirdOpponent.Resources.Count.ShouldBe(0);
        }
Esempio n. 2
0
        public void UseMonopolyCard_UseDevelopmentCard_ReceiveAllResourcesOfRequestedTypeFromOpponents()
        {
            // Arrange
            var monopolyCard        = new MonopolyDevelopmentCard();
            var testInstances       = this.TestSetup(new MockGameBoardWithNoResourcesCollected(), monopolyCard);
            var localGameController = testInstances.LocalGameController;

            testInstances.Dice.AddSequenceWithRepeatingRoll(null, 8);

            var player         = testInstances.MainPlayer;
            var firstOpponent  = testInstances.FirstOpponent;
            var secondOpponent = testInstances.SecondOpponent;
            var thirdOpponent  = testInstances.ThirdOpponent;

            player.AddResources(ResourceClutch.DevelopmentCard);
            firstOpponent.AddResources(ResourceClutch.OneOfEach);
            secondOpponent.AddResources(ResourceClutch.OneBrick * 2);
            thirdOpponent.AddResources(new ResourceClutch(0, 1, 1, 1, 1));

            GameToken turnToken = null;

            localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; };

            ResourceTransactionList gainedResources = null;

            localGameController.ResourcesTransferredEvent = (ResourceTransactionList r) => { gainedResources = r; };

            localGameController.StartGamePlay();

            // Buy the monopoly card
            localGameController.BuyDevelopmentCard(turnToken);
            localGameController.EndTurn(turnToken);

            // Act
            localGameController.UseMonopolyCard(turnToken, monopolyCard, ResourceTypes.Brick);

            // Assert
            var expectedResources = new ResourceTransactionList();

            expectedResources.Add(new ResourceTransaction(player.Id, firstOpponent.Id, ResourceClutch.OneBrick));
            expectedResources.Add(new ResourceTransaction(player.Id, secondOpponent.Id, ResourceClutch.OneBrick * 2));

            gainedResources.ShouldBe(expectedResources);
            player.Resources.Count.ShouldBe(3);
            player.Resources.BrickCount.ShouldBe(3);
            firstOpponent.Resources.Count.ShouldBe(4);
            firstOpponent.Resources.BrickCount.ShouldBe(0);
            secondOpponent.Resources.Count.ShouldBe(0);
            thirdOpponent.Resources.Count.ShouldBe(4);
            thirdOpponent.Resources.BrickCount.ShouldBe(0);
        }
        public void Equals_DifferentResourceCountOnEachEvent_ReturnsFalse()
        {
            var playerId   = Guid.NewGuid();
            var opponentId = Guid.NewGuid();
            var firstResourceTransactionList = new ResourceTransactionList();

            firstResourceTransactionList.Add(new ResourceTransaction(playerId, opponentId, ResourceClutch.OneBrick));

            var secondResourceTransactionList = new ResourceTransactionList();

            secondResourceTransactionList.Add(new ResourceTransaction(playerId, opponentId, ResourceClutch.OneBrick));
            secondResourceTransactionList.Add(new ResourceTransaction(playerId, opponentId, ResourceClutch.OneGrain));
            ((new PlayMonopolyCardEvent(playerId, firstResourceTransactionList)).Equals(new PlayMonopolyCardEvent(playerId, secondResourceTransactionList))).ShouldBeFalse();
        }
        public void Equals_SameResourcesOnBothEvents_ReturnsTrue()
        {
            var playerId = Guid.NewGuid();
            var resourceTransactionList = new ResourceTransactionList();

            resourceTransactionList.Add(new ResourceTransaction(playerId, Guid.NewGuid(), ResourceClutch.OneBrick));
            ((new PlayMonopolyCardEvent(playerId, resourceTransactionList)).Equals(new PlayMonopolyCardEvent(playerId, resourceTransactionList))).ShouldBeTrue();
        }
        public void Equals_OneResourcesOnOneEvent_ReturnsFalse()
        {
            var playerId = Guid.NewGuid();
            var resourceTransactionList = new ResourceTransactionList();

            resourceTransactionList.Add(new ResourceTransaction(playerId, Guid.NewGuid(), ResourceClutch.OneBrick));
            ((new PlayMonopolyCardEvent(playerId, resourceTransactionList)).Equals(new PlayMonopolyCardEvent(playerId, null))).ShouldBeFalse();
        }
        public void Scenario_OpponentUsesYearOfPlentyCardAndGetsResourcesofDifferentTypes()
        {
            // Arrange
            var bankId              = Guid.NewGuid();
            var yearOfPlentyCard    = new YearOfPlentyDevelopmentCard();
            var testInstances       = this.TestSetupWithExplictGameBoard(bankId, yearOfPlentyCard, new MockGameBoardWithNoResourcesCollected());
            var localGameController = testInstances.LocalGameController;

            testInstances.Dice.AddSequence(new uint[] { 8, 8, 8, 8, 8, 8, 8, 8 });

            var player         = testInstances.MainPlayer;
            var firstOpponent  = testInstances.FirstOpponent;
            var secondOpponent = testInstances.SecondOpponent;
            var thirdOpponent  = testInstances.ThirdOpponent;

            firstOpponent.AddResources(ResourceClutch.DevelopmentCard);
            firstOpponent.AddBuyDevelopmentCardChoice(1).EndTurn()
            .AddPlayYearOfPlentyCardInstruction(new PlayYearOfPlentyCardInstruction {
                FirstResourceChoice = ResourceTypes.Brick, SecondResourceChoice = ResourceTypes.Grain
            }).EndTurn();

            var       turn      = 0;
            GameToken turnToken = null;

            localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; turn++; };

            var gameEvents = new List <List <GameEvent> >();

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

            localGameController.StartGamePlay();
            localGameController.EndTurn(turnToken); // Opponent buys development card
            localGameController.EndTurn(turnToken); // Opponent plays year of plenty card

            // Assert
            var expectedBuyDevelopmentCardEvent = new BuyDevelopmentCardEvent(firstOpponent.Id);

            var expectedResourceTransactionList = new ResourceTransactionList();

            expectedResourceTransactionList.Add(new ResourceTransaction(firstOpponent.Id, bankId, new ResourceClutch(1, 1, 0, 0, 0)));
            var expectedPlayYearOfPlentyCardEvent = new YearOfPlentyCardPlayedEvent(firstOpponent.Id, ResourceTypes.Brick, ResourceTypes.Brick);

            gameEvents.Count.ShouldBe(15);
            gameEvents[2].Count.ShouldBe(2);
            gameEvents[2][1].ShouldBe(expectedBuyDevelopmentCardEvent);
            gameEvents[9].Count.ShouldBe(2);
            gameEvents[9][1].ShouldBe(expectedPlayYearOfPlentyCardEvent);

            player.Resources.Count.ShouldBe(0);
            firstOpponent.Resources.Count.ShouldBe(2);
            firstOpponent.Resources.BrickCount.ShouldBe(1);
            firstOpponent.Resources.GrainCount.ShouldBe(1);
            secondOpponent.Resources.Count.ShouldBe(0);
            secondOpponent.Resources.BrickCount.ShouldBe(0);
            thirdOpponent.Resources.Count.ShouldBe(0);
        }
        public void TradeWithBank_LegitmateResourcesForTransaction_ResourceTransactionCompleted(Int32 brickCount, Int32 receivingCount, Int32 otherCount, Int32 leftOverBrickCount)
        {
            // Arrange
            var bankId              = Guid.NewGuid();
            var testInstances       = this.TestSetupWithExplictGameBoard(bankId, new MockGameBoardWithNoResourcesCollected());
            var localGameController = testInstances.LocalGameController;

            var paymentResources   = ResourceClutch.OneBrick * (receivingCount * 4);
            var requestedResources = ResourceClutch.OneGrain * receivingCount;

            var player = testInstances.MainPlayer;

            player.AddResources(ResourceClutch.OneBrick * brickCount);
            player.AddResources(ResourceClutch.OneWool * otherCount);

            GameToken turnToken = null;

            localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; };

            ResourceTransactionList resources = null;

            localGameController.ResourcesTransferredEvent = (ResourceTransactionList r) => { resources = r; };

            localGameController.StartGamePlay();

            // Act
            localGameController.TradeWithBank(turnToken, ResourceTypes.Grain, receivingCount, ResourceTypes.Brick);

            // Assert
            resources.ShouldNotBeNull();

            var expected = new ResourceTransactionList();

            expected.Add(new ResourceTransaction(bankId, player.Id, paymentResources));
            expected.Add(new ResourceTransaction(player.Id, bankId, requestedResources));

            resources.ShouldBe(expected);

            player.Resources.Count.ShouldBe(receivingCount + otherCount + leftOverBrickCount);
            player.Resources.BrickCount.ShouldBe(leftOverBrickCount);
            player.Resources.GrainCount.ShouldBe(receivingCount);
            player.Resources.WoolCount.ShouldBe(otherCount);
        }
Esempio n. 8
0
        public ScenarioRunner ReceivesMonopolyCardPlayedEvent(Dictionary <string, ResourceClutch> resourcesByPlayerName, string playerName = null)
        {
            var playerId = playerName != null ? this.playerAgentsByName[playerName].Id : this.currentPlayerAgent.Id;
            var resourceTransactionList = new ResourceTransactionList();

            if (resourcesByPlayerName != null && resourcesByPlayerName.Count > 0)
            {
                foreach (var kv in resourcesByPlayerName)
                {
                    resourceTransactionList.Add(new ResourceTransaction(playerId, this.playerAgentsByName[kv.Key].Id, kv.Value));
                }
            }
            var gameEvent        = new PlayMonopolyCardEvent(playerId, resourceTransactionList);
            var eventInstruction = new EventInstruction(gameEvent);

            this.currentPlayerAgent.AddInstruction(eventInstruction);
            return(this);
        }
        public void UseYearOfPlentyCard_UseDevelopmentCard_DifferentResourcesAreCollected()
        {
            // Arrange
            var bankId              = Guid.NewGuid();
            var yearOfPlentyCard    = new YearOfPlentyDevelopmentCard();
            var testInstances       = this.TestSetupWithExplictGameBoard(bankId, yearOfPlentyCard, new MockGameBoardWithNoResourcesCollected());
            var localGameController = testInstances.LocalGameController;
            var player              = testInstances.MainPlayer;

            testInstances.Dice.AddSequenceWithRepeatingRoll(null, 8);
            testInstances.MainPlayer.AddResources(ResourceClutch.DevelopmentCard);

            GameToken turnToken = null;

            localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; };

            ResourceTransactionList resources = null;

            localGameController.ResourcesTransferredEvent = (ResourceTransactionList r) => { resources = r; };

            localGameController.StartGamePlay();

            // Buy the year of plenty card
            localGameController.BuyDevelopmentCard(turnToken);
            localGameController.EndTurn(turnToken);

            // Act
            localGameController.UseYearOfPlentyCard(turnToken, yearOfPlentyCard, ResourceTypes.Brick, ResourceTypes.Grain);

            // Assert
            var expected = new ResourceTransactionList();

            expected.Add(new ResourceTransaction(player.Id, bankId, new ResourceClutch(1, 1, 0, 0, 0)));

            resources.ShouldBe(expected);
            player.Resources.Count.ShouldBe(2);
            player.Resources.BrickCount.ShouldBe(1);
            player.Resources.GrainCount.ShouldBe(1);
        }