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 GetTotalTime()
        {
            _logger.LogInformation("class PlayerStatisticsMenu. GetTotalTime()");

            var response = await _statisticClient.GetUserGameTimeAsync();

            _logger.LogInformation("REQUEST: Sent the request to get the statistics");

            if (response.StatusCode == HttpStatusCode.OK)
            {
                _logger.LogInformation("RESPONSE: Get the Statistics (200)");

                var time = await response.Content.ReadAsStringAsync();

                time = JsonSerializer.Deserialize <string>(time);

                MenuLibrary.WriteColor("\nTotal time in the game: ", ConsoleColor.Yellow);
                MenuLibrary.WriteLineColor(time, ConsoleColor.White);

                MenuLibrary.PressAnyKey();
            }
            else
            {
                _logger.LogInformation("RESPONSE: Unknown response");
                throw new HttpListenerException();
            }
        }
 public void PrintHeader()
 {
     MenuLibrary.Clear();
     MenuLibrary.WriteLineColor("\nGame\n", ConsoleColor.Yellow);
     MenuLibrary.WriteColor("Results: ", ConsoleColor.White);
     MenuLibrary.WriteColor($"{_sessionResults.WinCount} : ", ConsoleColor.Green);
     MenuLibrary.WriteColor($"{_sessionResults.DrawCount} : ", ConsoleColor.Yellow);
     MenuLibrary.WriteLineColor($"{_sessionResults.LossesCount}", ConsoleColor.Red);
 }
        private void ShowRate(List <UserResultDto> results)
        {
            MenuLibrary.WriteLineColor("", ConsoleColor.White);
            int place = 1;

            foreach (var result in results)
            {
                MenuLibrary.WriteColor($"{place}. {result.Login}: ", ConsoleColor.White);
                MenuLibrary.WriteLineColor(result.Result, ConsoleColor.Yellow);
                place++;
            }
            MenuLibrary.PressAnyKey();
        }
示例#5
0
        private void ShowRate(List <ResultByTimeDto> results)
        {
            MenuLibrary.WriteLineColor("", ConsoleColor.White);
            int place = 1;

            foreach (var result in results)
            {
                MenuLibrary.WriteColor($"{place}. {result.Time} -> ", ConsoleColor.White);
                MenuLibrary.WriteColor(result.WinCount.ToString(), ConsoleColor.Green);
                MenuLibrary.WriteColor(" : ", ConsoleColor.White);
                MenuLibrary.WriteLineColor(result.LossCount.ToString(), ConsoleColor.Red);
                place++;
            }
            MenuLibrary.PressAnyKey();
        }
        private async Task GameStartAsync(RoomType roomType, string roomId)
        {
            _logger.LogInformation("class GameStartMenu. GameStartAsync()");

            var response = await _gameClient.StartSessionAsync(roomType, roomId);

            _logger.LogInformation("REQUEST: Sent the request to the server to start the game");

            if (response.StatusCode == HttpStatusCode.OK)
            {
                _logger.LogInformation("RESPONSE: Game successfully started (200)");

                MenuLibrary.WriteLineColor("\nSuccessfully started game\n", ConsoleColor.Green);

                if (roomType == RoomType.Private && roomId == null)
                {
                    var roomNumber = await response.Content.ReadAsStringAsync();

                    roomNumber = JsonSerializer.Deserialize <string>(roomNumber);

                    MenuLibrary.WriteColor("Your room number: ", ConsoleColor.White);
                    MenuLibrary.WriteLineColor(roomNumber, ConsoleColor.Green);
                    MenuLibrary.WriteLineColor("Say it your friend to connection.", ConsoleColor.White);
                }
                MenuLibrary.WriteLineColor("\nWait for the opponent...\n", ConsoleColor.DarkCyan);

                await WaitPlayerAsync();
            }
            else if (response.StatusCode == HttpStatusCode.BadRequest ||
                     response.StatusCode == HttpStatusCode.Conflict)
            {
                _logger.LogInformation("RESPONSE: Did not manage to start the game (400, 409)");
                await ResponseLibrary.RepeatOperationWithMessageAsync <string>(response);
            }
            else
            {
                _logger.LogInformation("RESPONSE: Unknown response");
                throw new HttpListenerException();
            }
        }
        public void PrintResult(RoundResultDto result)
        {
            string       resultString = "";
            ConsoleColor color        = ConsoleColor.White;

            switch (result.Result)
            {
            case 1:
                _sessionResults.WinCount++;
                resultString = "Win";
                color        = ConsoleColor.Green;
                break;

            case 0:
                _sessionResults.DrawCount++;
                resultString = "Draw";
                color        = ConsoleColor.Yellow;
                break;

            case -1:
                _sessionResults.LossesCount++;
                resultString = "Lose";
                color        = ConsoleColor.Red;
                break;
            }

            PrintHeader();

            MenuLibrary.WriteColor($"\nYour move: ", ConsoleColor.White);
            MenuLibrary.WriteLineColor($"{_currentMove}", ConsoleColor.DarkCyan);

            MenuLibrary.WriteColor($"Opponent move: ", ConsoleColor.White);
            MenuLibrary.WriteLineColor($"{result.OpponentMove}", ConsoleColor.DarkCyan);

            MenuLibrary.WriteColor($"\nResult: ", ConsoleColor.White);
            MenuLibrary.WriteLineColor(resultString, color);

            MenuLibrary.PressAnyKey();
        }