public async static Task run(HttpClient client) { IApiClient apiClient = new ApiClient(client); IGameAccess newAccess = await GameAccess.Create(apiClient, "Pinky and the Brain"); WarRoom board = new WarRoom(newAccess); Console.WriteLine($"Game: {newAccess.GameId}"); int waitCount = 0; while (waitCount < 10) { TurnStatus state = await board.TakeTurn(); switch (state) { case TurnStatus.TookTurn: Console.WriteLine("And so my watch has ended (for now)"); waitCount = 0; break; case TurnStatus.Waiting: Console.WriteLine("Waits patiently..."); waitCount++; break; case TurnStatus.LostGame: Console.WriteLine($"Valar Morghulis"); return; case TurnStatus.WonGame: Console.WriteLine($"Hail to the King!"); return; default: Console.WriteLine("Status Unavailable"); break; } Thread.Sleep(1000); //optimize } }
public async Task TakeTurnReturnsStatus(bool currentTurn, int?winner, TurnStatus status) { GameResult mockedResult = new GameResult() { player = 1 }; PlayerState mockedState = new PlayerState() { winner = winner, current_turn = currentTurn, territories = new Territory[] { new Territory() { territory = 1, territory_name = "" } } }; mockAccess.Setup(a => a.CurrentPlayer).Returns(1); mockAccess.Setup(a => a.GetPlayerState()).ReturnsAsync(mockedState); mockAccess.Setup(a => a.PlaceArmies(It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(true); TurnStatus actual = await board.TakeTurn(); Assert.Equal(status, actual); }