protected LocalGameController CreateLocalGameController(INumberGenerator dice, IPlayerFactory playerPool, IDevelopmentCardHolder developmentCardHolder) { var localGameControllerCreator = new LocalGameControllerCreator(); if (dice != null) { localGameControllerCreator.ChangeDice(dice); } if (playerPool != null) { localGameControllerCreator.ChangePlayerPool(playerPool); } if (developmentCardHolder != null) { localGameControllerCreator.ChangeDevelopmentCardHolder(developmentCardHolder); } var localGameController = localGameControllerCreator.Create(); localGameController.ErrorRaisedEvent = (ErrorDetails e) => { throw new Exception(e.Message); }; return(localGameController); }
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(); }
public void LaunchGame_LaunchGameWithoutJoining_MeaningfulErrorIsReceived() { var localGameController = new LocalGameControllerCreator().Create(); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.LaunchGame(); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot call 'LaunchGame' without joining game."); }
public void CompleteGameSetup_CallOutOfSequence_MeaningfulErrorIsReceived() { var localGameController = new LocalGameControllerCreator().Create(); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.CompleteGameSetup(0u, 1u); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot call 'CompleteGameSetup' until 'ContinueGameSetup' has completed."); }
protected LocalGameController CreateLocalGameController(INumberGenerator dice, IPlayer firstPlayer, params IPlayer[] otherPlayers) { var mockPlayerPool = LocalGameControllerTestCreator.CreateMockPlayerPool(firstPlayer, otherPlayers); var localGameController = new LocalGameControllerCreator() .ChangeDice(dice) .ChangePlayerPool(mockPlayerPool) .Create(); localGameController.ErrorRaisedEvent = (ErrorDetails e) => { throw new Exception(e.Message); }; return(localGameController); }
public void Load_PlayerDataOnly_PlayerDataViewsAreAsExpected() { // Arrange MockPlayer player; MockComputerPlayer firstOpponent, secondOpponent, thirdOpponent; this.CreateDefaultPlayerInstances(out player, out firstOpponent, out secondOpponent, out thirdOpponent); player.AddResources(new ResourceClutch(1, 2, 3, 4, 5)); firstOpponent.AddResources(new ResourceClutch(1, 1, 1, 1, 1)); secondOpponent.AddResources(new ResourceClutch(2, 2, 2, 2, 2)); thirdOpponent.AddResources(new ResourceClutch(3, 3, 3, 3, 3)); var localGameController = new LocalGameControllerCreator().Create(); PlayerDataBase[] playerDataViews = null; localGameController.GameLoadedEvent = (PlayerDataBase[] pd, GameBoard bd) => { playerDataViews = pd; }; // Act var streamContent = "<game>" + "<players>" + "<player id=\"" + player.Id + "\" name=\"" + player.Name + "\" brick=\"" + player.Resources.BrickCount + "\" grain=\"" + player.Resources.GrainCount + "\" lumber=\"" + player.Resources.LumberCount + "\" ore=\"" + player.Resources.OreCount + "\" wool=\"" + player.Resources.WoolCount + "\" />" + "<player id=\"" + firstOpponent.Id + "\" name=\"" + firstOpponent.Name + "\" iscomputer=\"true\" brick=\"" + firstOpponent.Resources.BrickCount + "\" grain=\"" + firstOpponent.Resources.GrainCount + "\" lumber=\"" + firstOpponent.Resources.LumberCount + "\" ore=\"" + firstOpponent.Resources.OreCount + "\" wool=\"" + firstOpponent.Resources.WoolCount + "\" />" + "<player id=\"" + secondOpponent.Id + "\" name=\"" + secondOpponent.Name + "\" iscomputer=\"true\" brick=\"" + secondOpponent.Resources.BrickCount + "\" grain=\"" + secondOpponent.Resources.GrainCount + "\" lumber=\"" + secondOpponent.Resources.LumberCount + "\" ore=\"" + secondOpponent.Resources.OreCount + "\" wool=\"" + secondOpponent.Resources.WoolCount + "\" />" + "<player id=\"" + thirdOpponent.Id + "\" name=\"" + thirdOpponent.Name + "\" iscomputer=\"true\" brick=\"" + thirdOpponent.Resources.BrickCount + "\" grain=\"" + thirdOpponent.Resources.GrainCount + "\" lumber=\"" + thirdOpponent.Resources.LumberCount + "\" ore=\"" + thirdOpponent.Resources.OreCount + "\" wool=\"" + thirdOpponent.Resources.WoolCount + "\" />" + "</players>" + "</game>"; var streamContentBytes = Encoding.UTF8.GetBytes(streamContent); using (var stream = new MemoryStream(streamContentBytes)) { localGameController.Load(stream); } // Assert playerDataViews.ShouldNotBeNull(); playerDataViews.Length.ShouldBe(4); this.AssertPlayerDataViewIsCorrect(player, (PlayerDataModel)playerDataViews[0]); this.AssertPlayerDataViewIsCorrect(firstOpponent, (PlayerDataModel)playerDataViews[1]); this.AssertPlayerDataViewIsCorrect(secondOpponent, (PlayerDataModel)playerDataViews[2]); this.AssertPlayerDataViewIsCorrect(thirdOpponent, (PlayerDataModel)playerDataViews[3]); }
public void TryingToJoinGameMoreThanOnce_MeaningfulErrorIsReceived() { 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().ChangePlayerPool(mockPlayerFactory).Create(); ErrorDetails errorDetails = null; localGameController.ErrorRaisedEvent = (ErrorDetails e) => { errorDetails = e; }; localGameController.JoinGame(); localGameController.JoinGame(); errorDetails.ShouldNotBeNull(); errorDetails.Message.ShouldBe("Cannot call 'JoinGame' more than once."); }
public void Load_HexDataOnly_ResourceProvidersLoadedCorrectly() { // Arrange var localGameController = new LocalGameControllerCreator().Create(); GameBoard boardData = null; localGameController.GameLoadedEvent = (PlayerDataBase[] pd, GameBoard bd) => { boardData = bd; }; // Act var content = "<game><board><hexes>" + "<resources>glbglogob gwwwlwlbo</resources>" + "<production>9,8,5,12,11,3,6,10,6,0,4,11,2,4,3,5,9,10,8</production>" + "</hexes></board></game>"; var contentBytes = Encoding.UTF8.GetBytes(content); using (var memoryStream = new MemoryStream(contentBytes)) { localGameController.Load(memoryStream); } // Assert boardData.ShouldNotBeNull(); HexInformation[] hexes = boardData.GetHexData(); hexes.Length.ShouldBe(GameBoard.StandardBoardHexCount); hexes[0].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Grain, ProductionFactor = 9 }); hexes[1].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Lumber, ProductionFactor = 8 }); hexes[2].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Brick, ProductionFactor = 5 }); hexes[3].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Grain, ProductionFactor = 12 }); hexes[4].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Lumber, ProductionFactor = 11 }); hexes[5].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Ore, ProductionFactor = 3 }); hexes[6].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Grain, ProductionFactor = 6 }); hexes[7].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Ore, ProductionFactor = 10 }); hexes[8].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Brick, ProductionFactor = 6 }); hexes[9].ShouldBe(new HexInformation { ResourceType = null, ProductionFactor = 0 }); hexes[10].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Grain, ProductionFactor = 4 }); hexes[11].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Wool, ProductionFactor = 11 }); hexes[12].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Wool, ProductionFactor = 2 }); hexes[13].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Wool, ProductionFactor = 4 }); hexes[14].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Lumber, ProductionFactor = 3 }); hexes[15].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Wool, ProductionFactor = 5 }); hexes[16].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Lumber, ProductionFactor = 9 }); hexes[17].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Brick, ProductionFactor = 10 }); hexes[18].ShouldBe(new HexInformation { ResourceType = ResourceTypes.Ore, ProductionFactor = 8 }); }