示例#1
0
        public async Task StartAsync()
        {
            _logger.LogInformation("class UserMenu. StartAsync()");

            while (true)
            {
                _logger.LogInformation("Choosing the option");

                MenuLibrary.Clear();

                var options = new string[] { "Game", "Statistics", "Logout" };
                var command = MenuLibrary.InputMenuItemNumber("User Menu", options);

                _logger.LogInformation("Chose the command");

                switch (command)
                {
                case 1:
                    await _gameStartMenu.StartAsync();

                    break;

                case 2:
                    await _statisticsMenu.StartAsync();

                    break;

                case 3:
                    return;
                }
            }
        }
示例#2
0
        public async Task StartAsync()
        {
            _logger.LogInformation("class MainMenu. StartAsync()");

            while (true)
            {
                MenuLibrary.Clear();

                _logger.LogInformation("Choosing the command");

                var options = new string[] { "Authorization", "Leaderboard", "Exit" };
                var command = MenuLibrary.InputMenuItemNumber("Main Menu", options);

                _logger.LogInformation("Chose the command");

                switch (command)
                {
                case 1:
                    await _authMenu.StartAsync();

                    break;

                case 2:
                    await _leaderMenu.StartAsync();

                    break;

                case 3:
                    return;
                }
            }
        }
        public async Task StartAsync()
        {
            _logger.LogInformation("class StatisticsMenu. StartAsync()");

            while (true)
            {
                _logger.LogInformation("Choosing the Statistics");

                MenuLibrary.Clear();

                var options = new string[] { "Leaderboard", "Player statistics", "Back" };
                var command = MenuLibrary.InputMenuItemNumber("Statistics Menu", options);

                _logger.LogInformation("Chose the command");

                switch (command)
                {
                case 1:
                    await _leaderboardMenu.StartAsync();

                    break;

                case 2:
                    await _playerStatisticsMenu.StartAsync();

                    break;

                case 3:
                    return;
                }
            }
        }
示例#4
0
        private async Task <string> GetResultByIntervalAsync(TimeInterval timeInterval)
        {
            _logger.LogInformation("class IntervalResultsMenu. GetResultByIntervalAsync()");

            var options = new string[] { "Set the amount of last days/hours/minutes for statistics", "Show all days/hours/minutes for statistics" };
            var command = MenuLibrary.InputMenuItemNumber("Please, choose", options);

            var amount = command == 1
                ? MenuLibrary.InputIntegerValue("amount", 1, int.MaxValue)
                : int.MaxValue;

            var response = await _statisticClient.GetUserResultByIntervalAsync(amount, timeInterval);

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

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

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

                return(content);
            }
            else
            {
                _logger.LogInformation("RESPONSE: Unknown response");
                throw new HttpListenerException();
            }
        }
        private async Task <string> GetStatistcsAsync(StatisticsType type)
        {
            _logger.LogInformation("class LeaderboardMenu. GetStatistcsAsync()");

            var options = new string[] { "Set the amount of best players in the rate", "Show all players in the rate" };
            var command = MenuLibrary.InputMenuItemNumber("Please, choose", options);

            var amount = command == 1
                ? MenuLibrary.InputIntegerValue("amount", 1, int.MaxValue)
                : int.MaxValue;

            var response = await _statisticClient.GetLeaderboardAsync(amount, type);

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

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

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

                return(content);
            }
            else
            {
                _logger.LogInformation("RESPONSE: Unknown response");
                throw new HttpListenerException();
            }
        }
示例#6
0
        public async Task StartAsync()
        {
            _logger.LogInformation("class AuthorizationMenu. StartAsync()");
            while (true)
            {
                _logger.LogInformation("Choosing the Authorization Method");

                MenuLibrary.Clear();

                var options = new string[] { "Login", "Registration", "Back" };
                var command = MenuLibrary.InputMenuItemNumber("Authorization Menu", options);

                _logger.LogInformation("Chose the command");

                switch (command)
                {
                case 1:
                    await ExecuteLoginAsync();

                    break;

                case 2:
                    await ExecuteRegistrationAsync();

                    break;

                case 3:
                    return;
                }
            }
        }
        public async Task StartAsync()
        {
            _logger.LogInformation("class GameMenu. StartAsync()");

            while (true)
            {
                _logger.LogInformation("Choosing the move");

                PrintHeader();

                var options = new string[] { "Rock", "Paper", "Scissors", "Quit" };
                var command = MenuLibrary.InputMenuItemNumber("Choose command", options);

                _logger.LogInformation("Chose the command");

                Move move = Move.Rock;
                switch (command)
                {
                case 1:
                    move = Move.Rock;
                    break;

                case 2:
                    move = Move.Paper;
                    break;

                case 3:
                    move = Move.Scissors;
                    break;

                case 4:
                    _logger.LogInformation("REQUEST: Sending the request to finish the session");
                    await _gameClient.FinishSessionAsync();

                    return;
                }

                var success = await DoMoveAsync(move);

                if (!success)
                {
                    return;
                }

                success = await CheckMoveAsync();

                if (!success)
                {
                    return;
                }
            }
        }
        private string ChoosePrivateRoom()
        {
            var options = new string[] { "Start private room", "Connect to private room" };
            var command = MenuLibrary.InputMenuItemNumber("Private room Menu", options);

            if (command == 1)
            {
                return(null);
            }
            else
            {
                return(MenuLibrary.InputStringValue("room number"));
            }
        }
示例#9
0
        public async Task StartAsync()
        {
            _logger.LogInformation("class IntervalResultsMenu. StartAsync()");

            while (true)
            {
                _logger.LogInformation("Choosing Time Interval");

                TimeInterval timeInterval = TimeInterval.Day;

                MenuLibrary.Clear();

                var options = new string[] { "By days", "By hours", "By minutes", "Back" };
                var command = MenuLibrary.InputMenuItemNumber("Leaderboard Menu", options);

                _logger.LogInformation("Chose the command");

                switch (command)
                {
                case 1:
                    timeInterval = TimeInterval.Day;
                    break;

                case 2:
                    timeInterval = TimeInterval.Hour;
                    break;

                case 3:
                    timeInterval = TimeInterval.Minute;
                    break;

                case 4:
                    return;
                }

                var content = await GetResultByIntervalAsync(timeInterval);

                if (content == null)
                {
                    continue;
                }

                var results = JsonSerializer.Deserialize <List <ResultByTimeDto> >(content);
                ShowRate(results);
            }
        }
        public async Task StartAsync()
        {
            _logger.LogInformation("class LeaderboardMenu. StartAsync()");

            while (true)
            {
                _logger.LogInformation("Choosing Statistics Type");

                StatisticsType statisticsType = StatisticsType.WinStatistics;

                MenuLibrary.Clear();

                var options = new string[] { "Win statistics", "Time statistics", "Wins statistics(in persents)", "Back" };
                var command = MenuLibrary.InputMenuItemNumber("Leaderboard Menu", options);

                _logger.LogInformation("Chose the command");

                switch (command)
                {
                case 1:
                    statisticsType = StatisticsType.WinStatistics;
                    break;

                case 2:
                    statisticsType = StatisticsType.TimeStatistics;
                    break;

                case 3:
                    statisticsType = StatisticsType.WinPercentStatistics;
                    break;

                case 4:
                    return;
                }

                var content = await GetStatistcsAsync(statisticsType);

                if (content == null)
                {
                    continue;
                }

                var results = JsonSerializer.Deserialize <List <UserResultDto> >(content);
                ShowRate(results);
            }
        }
        public async Task StartAsync()
        {
            _logger.LogInformation("class PlayerStatisticsMenu. StartAsync()");

            while (true)
            {
                _logger.LogInformation("Choosing the Statistics Type");

                MenuLibrary.Clear();

                var options = new string[] { "Total results", "Total playing time", "Moves statistics", "Results by the time", "Back" };
                var command = MenuLibrary.InputMenuItemNumber("Player statistics Menu", options);

                _logger.LogInformation("Chose the command");

                switch (command)
                {
                case 1:
                    await GetResults();

                    break;

                case 2:
                    await GetTotalTime();

                    break;

                case 3:
                    await GetMovesStatistics();

                    break;

                case 4:
                    await _intervalResultsMenu.StartAsync();

                    break;

                case 5:
                    return;
                }
            }
        }
        public async Task StartAsync()
        {
            _logger.LogInformation("class GameStartMenu. StartAsync()");

            while (true)
            {
                _logger.LogInformation("Choosing the game type");

                MenuLibrary.Clear();

                var options = new string[] { "Public game", "Private game", "Train game", "Back" };
                var command = MenuLibrary.InputMenuItemNumber("Game Menu", options);

                _logger.LogInformation("Chose the command");

                RoomType roomType;
                string   roomId = null;

                switch (command)
                {
                case 1:
                    roomType = RoomType.Public;
                    break;

                case 2:
                    roomType = RoomType.Private;
                    roomId   = ChoosePrivateRoom();
                    break;

                case 3:
                    roomType = RoomType.Train;
                    break;

                case 4:
                default:
                    return;
                }

                await GameStartAsync(roomType, roomId);
            }
        }