public async Task <bool> DoMoveAsync(Move move) { _logger.LogInformation("class GameMenu. DoMoveAsync()"); var response = await _gameClient.DoMoveAsync(move); _logger.LogInformation("REQUEST: Sent the request to the server to do the move"); if (response.StatusCode == HttpStatusCode.OK) { _logger.LogInformation("RESPONSE: Successful response (200)"); _currentMove = move; PrintHeader(); MenuLibrary.WriteColor($"\nYour move: ", ConsoleColor.White); MenuLibrary.WriteLineColor($"{_currentMove}", ConsoleColor.DarkCyan); return(true); } else if (response.StatusCode == HttpStatusCode.Conflict) { _logger.LogInformation("RESPONSE: Game is over (409)"); await ResponseLibrary.GameFinishedResponseAsync(response); } else { _logger.LogInformation("RESPONSE: Unknown response"); throw new HttpListenerException(); } return(false); }
private async Task WaitPlayerAsync() { _logger.LogInformation("class GameStartMenu. WaitPlayerAsync()"); while (true) { var response = await _gameClient.CheckSessionAsync(); _logger.LogInformation("REQUEST: Sent the request to check the opponent"); if (response.StatusCode == HttpStatusCode.OK) { _logger.LogInformation("RESPONSE: Opponent was found (200)"); var name = await response.Content.ReadAsStringAsync(); name = JsonSerializer.Deserialize <string>(name); MenuLibrary.WriteLineColor($"\nYour opponent is {name}\n", ConsoleColor.Green); Thread.Sleep(2000); await _gameMenu.StartAsync(); return; } else if (response.StatusCode == HttpStatusCode.Conflict) { _logger.LogInformation("RESPONSE: Game is over (409)"); await ResponseLibrary.GameFinishedResponseAsync(response); return; } else if (response.StatusCode != HttpStatusCode.NotFound) { _logger.LogInformation("RESPONSE: Unknown response"); throw new HttpListenerException(); } _logger.LogInformation("RESPONSE: Opponnent was not found (404)"); Thread.Sleep(200); } }
public async Task <bool> CheckMoveAsync() { _logger.LogInformation("class GameMenu. CheckMoveAsync()"); MenuLibrary.WriteLineColor("\nWait opponent...", ConsoleColor.DarkCyan); while (true) { var response = await _gameClient.CheckMoveAsync(); _logger.LogInformation("REQUEST: Sent the request to check the move"); if (response.StatusCode == HttpStatusCode.OK) { _logger.LogInformation("RESPONSE: Player did a move (200)"); var resultJson = await response.Content.ReadAsStringAsync(); var result = JsonSerializer.Deserialize <RoundResultDto>(resultJson); PrintResult(result); return(true); } else if (response.StatusCode == HttpStatusCode.Conflict) { _logger.LogInformation("RESPONSE: Game is over (409)"); await ResponseLibrary.GameFinishedResponseAsync(response); return(false); } else if (response.StatusCode != HttpStatusCode.NotFound) { _logger.LogInformation("RESPONSE: Unknown response"); throw new HttpListenerException(); } _logger.LogInformation("RESPONSE: The opponent did not do the move (404)"); Thread.Sleep(200); } }