public void UseMonopolyCard_UseCardPurchasedInSameTurn_MeaningfulErrorIsReceived() { // Arrange var monopolyCard = new MonopolyDevelopmentCard(); var testInstances = this.TestSetup(monopolyCard); var localGameController = testInstances.LocalGameController; testInstances.MainPlayer.AddResources(ResourceClutch.DevelopmentCard); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; DevelopmentCard purchasedDevelopmentCard = null; localGameController.DevelopmentCardPurchasedEvent = (DevelopmentCard d) => { purchasedDevelopmentCard = d; }; localGameController.StartGamePlay(); localGameController.BuyDevelopmentCard(turnToken); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; // Act localGameController.UseMonopolyCard(turnToken, (MonopolyDevelopmentCard)purchasedDevelopmentCard, ResourceTypes.Brick); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot use development card that has been purchased this turn."); }
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); }
public void UseMonopolyCard_UseDevelopmentCardMoreThanOnce_MeaningfulErrorIsReceived() { // Arrange var monopolyCard = new MonopolyDevelopmentCard(); var testInstances = this.TestSetup(monopolyCard); var localGameController = testInstances.LocalGameController; testInstances.Dice.AddSequenceWithRepeatingRoll(null, 6); testInstances.MainPlayer.AddResources(ResourceClutch.DevelopmentCard); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; localGameController.StartGamePlay(); // Buy the knight cards localGameController.BuyDevelopmentCard(turnToken); localGameController.EndTurn(turnToken); // Play one knight card each turn for the next two turns localGameController.UseMonopolyCard(turnToken, monopolyCard, ResourceTypes.Brick); localGameController.EndTurn(turnToken); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; // Act localGameController.UseMonopolyCard(turnToken, monopolyCard, ResourceTypes.Brick); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot play the same development card more than once."); }
public void UseMonopolyCard_GameIsOver_MeaningfulErrorIsReceived() { // Arrange var testInstances = this.TestSetup(new MockGameBoardWithNoResourcesCollected(), new MonopolyDevelopmentCard()); var localGameController = testInstances.LocalGameController; testInstances.Dice.AddSequenceWithRepeatingRoll(null, 6); var player = testInstances.MainPlayer; player.AddResources(ResourceClutch.RoadSegment * 5); player.AddResources(ResourceClutch.Settlement * 3); player.AddResources(ResourceClutch.City * 4); player.AddResources(ResourceClutch.DevelopmentCard); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; MonopolyDevelopmentCard monopolyCard = null; localGameController.DevelopmentCardPurchasedEvent = (DevelopmentCard d) => { monopolyCard = (MonopolyDevelopmentCard)d; }; localGameController.StartGamePlay(); localGameController.BuyDevelopmentCard(turnToken); localGameController.EndTurn(turnToken); localGameController.BuildRoadSegment(turnToken, 4u, 3u); localGameController.BuildRoadSegment(turnToken, 3u, 2u); localGameController.BuildRoadSegment(turnToken, 2u, 1u); localGameController.BuildRoadSegment(turnToken, 1u, 0u); // Got 2VP for longest road (4VP) localGameController.BuildRoadSegment(turnToken, 2u, 10u); localGameController.BuildSettlement(turnToken, 3); localGameController.BuildSettlement(turnToken, 10); localGameController.BuildCity(turnToken, 3); localGameController.BuildCity(turnToken, 10); localGameController.BuildCity(turnToken, 12); localGameController.BuildCity(turnToken, 40); // Got 10VP, Game over event raised // Act localGameController.UseMonopolyCard(turnToken, monopolyCard, ResourceTypes.Brick); // Assert errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot use monopoly card. Game is over."); }
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 UseMonopolyCard_UseDevelopmentCardWhenOpponentsHaveNoResourcesOfType_ReceivedNullReference() { // Arrange var monopolyCard = new MonopolyDevelopmentCard(); var testInstances = this.TestSetup(new MockGameBoardWithNoResourcesCollected(), monopolyCard); var localGameController = testInstances.LocalGameController; testInstances.Dice.AddSequence(new uint[] { 8, 8, 8, 3, 8 }); var player = testInstances.MainPlayer; var firstOpponent = testInstances.FirstOpponent; var secondOpponent = testInstances.SecondOpponent; var thirdOpponent = testInstances.ThirdOpponent; player.AddResources(ResourceClutch.DevelopmentCard); firstOpponent.AddResources(ResourceClutch.OneGrain); secondOpponent.AddResources(ResourceClutch.OneLumber); thirdOpponent.AddResources(ResourceClutch.OneOre); GameToken turnToken = null; localGameController.StartPlayerTurnEvent = (GameToken t) => { turnToken = t; }; var gainedResources = new ResourceTransactionList(); // Ensure that state change can be recognised 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 gainedResources.ShouldBeNull(); player.Resources.Count.ShouldBe(0); firstOpponent.Resources.Count.ShouldBe(1); firstOpponent.Resources.GrainCount.ShouldBe(1); secondOpponent.Resources.Count.ShouldBe(1); secondOpponent.Resources.LumberCount.ShouldBe(1); thirdOpponent.Resources.Count.ShouldBe(1); thirdOpponent.Resources.OreCount.ShouldBe(1); }
public void AddDevelopmentCard(DevelopmentCardTypes developmentCardType) { DevelopmentCard developmentCard = null; switch (developmentCardType) { case DevelopmentCardTypes.Knight: developmentCard = new KnightDevelopmentCard(); break; case DevelopmentCardTypes.Monopoly: developmentCard = new MonopolyDevelopmentCard(); break; case DevelopmentCardTypes.RoadBuilding: developmentCard = new RoadBuildingDevelopmentCard(); break; case DevelopmentCardTypes.YearOfPlenty: developmentCard = new YearOfPlentyDevelopmentCard(); break; default: throw new NotImplementedException($"Development card type {developmentCardType} not recognised"); } this.developmentCards.Enqueue(developmentCard); }
private void Initialise(IIndexSequence random) { this.cards = new Queue <DevelopmentCard>(); var victoryPointCardTitles = new Queue <string>(new[] { "Chapel", "Great Hall", "Library", "Market", "University" }); var index = -1; while (random.TryGetNextIndex(out index)) { if (index < KnightCardCount) { var card = new KnightDevelopmentCard(); this.cards.Enqueue(card); } else if (index < (KnightCardCount + MonopolyCardCount)) { var card = new MonopolyDevelopmentCard(); this.cards.Enqueue(card); } else if (index < (KnightCardCount + MonopolyCardCount + RoadBuildingCardCount)) { var card = new RoadBuildingDevelopmentCard(); this.cards.Enqueue(card); } else if (index < (KnightCardCount + MonopolyCardCount + RoadBuildingCardCount + YearOfPlentyCardCount)) { var card = new YearOfPlentyDevelopmentCard(); this.cards.Enqueue(card); } else if (index < (KnightCardCount + MonopolyCardCount + RoadBuildingCardCount + YearOfPlentyCardCount + VictoryPointCardCount)) { var title = victoryPointCardTitles.Dequeue(); var card = new VictoryPointDevelopmentCard(title); this.cards.Enqueue(card); } } }