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 <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 static async Task <int> Main() { var provider = GetServiceProvider(); while (true) { try { MenuLibrary.Clear(); MenuLibrary.WriteLineColor("The Rock Paper Scissors Game. Designed by Karyna Bilotska and Daniil Panasenko\n", ConsoleColor.DarkGreen); MenuLibrary.PressAnyKey(); GetHttpClient(); var mainMemu = provider.GetRequiredService <MainMenu>(); await mainMemu.StartAsync(); return(0); } catch (Exception) { ResponseLibrary.UnknownResponse(); MenuLibrary.PressAnyKey(); } } }
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 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; } } }
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; } } }
public void Start() { menuLibrary = LibraryManager.instance.get <MenuLibrary>(); ingredientLibrary = LibraryManager.instance.get <IngredientLibrary>(); if (ingredientOverridePool.Count > 0) { ingredientsPool = ingredientOverridePool; } else { ingredientsPool = menuLibrary.getIngredients().Select((ingred) => ingred.type).ToList(); } foreach (IngredientType type in ingredientsPool) { ingredientsNotInUse.Add(type); } for (int a = 0; a < size; a++) { GameObject selector = Instantiate(ingredientSelector); selector.transform.SetParent(transform, false); setIngredientType(selector.GetComponent <IngredientHolder>(), getRandomIngredient()); selectors.Add(selector.GetComponent <IngredientHolder>()); } foreach (IngredientHolder ingredientHolder in selectors) { ingredientHolder.gameObject.GetComponent <OnEvent>().click += () => ingredientSelected(ingredientHolder); } ingredientSelected(selectors[0]); }
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(); } }
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(); } }
private async Task GetResults() { _logger.LogInformation("class PlayerStatisticsMenu. GetResults()"); var response = await _statisticClient.GetUserResultsAsync(); _logger.LogInformation("REQUEST: Sent the request to get the statistics"); if (response.StatusCode == HttpStatusCode.OK) { _logger.LogInformation("RESPONSE: Get the Statistics (200)"); var content = await response.Content.ReadAsStringAsync(); var results = JsonSerializer.Deserialize <ResultsDto>(content); MenuLibrary.WriteLineColor("\nYour results:\n", ConsoleColor.Yellow); MenuLibrary.WriteColor("Wins: ", ConsoleColor.Yellow); MenuLibrary.WriteLineColor(results.WinCount.ToString(), ConsoleColor.White); MenuLibrary.WriteColor("Draws: ", ConsoleColor.Yellow); MenuLibrary.WriteLineColor(results.DrawCount.ToString(), ConsoleColor.White); MenuLibrary.WriteColor("Losses: ", ConsoleColor.Yellow); MenuLibrary.WriteLineColor(results.LossCount.ToString(), ConsoleColor.White); MenuLibrary.PressAnyKey(); } else { _logger.LogInformation("RESPONSE: Unknown response"); throw new HttpListenerException(); } }
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 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); }
// Use this for initialization void Start() { buttonCG = GetComponent <ButtonCG>(); menuLibrary = LibraryManager.instance.get <MenuLibrary>(); menuLibrary.onFull += () => buttonCG.setEnabled(true); menuLibrary.onNotFull += () => buttonCG.setEnabled(false); menuLibrary.checkFull(); buttonCG.clicked += startDay; }
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 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(); }
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")); } }
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(); }
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 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); } }
private void Start() { menuLibrary = LibraryManager.instance.get <MenuLibrary>(); ingredientsHolders = GetComponentsInChildren <IngredientHolder>().ToList(); List <Ingredient> ingredients = menuLibrary.getIngredients(); for (int a = 0; a < ingredientsHolders.Count; a++) { if (a < ingredients.Count) { ingredientsHolders[a].setIngredient(ingredients[a]); } else { ingredientsHolders[a].setIngredient(null); } holderToIndex.Add(ingredientsHolders[a], a); } }
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; } } }
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 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); } }
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 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); } }
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(); }
private async Task ExecuteRegistrationAsync() { _logger.LogInformation("class AuthorizationMenu. ExecuteRegistrationAsync()"); MenuLibrary.Clear(); while (true) { MenuLibrary.WriteLineColor("\nRegistration\n", ConsoleColor.Yellow); string login = MenuLibrary.InputStringValue("login"); string password = MenuLibrary.InputStringValue("password"); _logger.LogInformation("Entered the login and the password"); var response = await _userClient.RegistrationAsync(login, password); _logger.LogInformation("REQUEST: Sent the register request to the server"); if (await ResponseHandlerAsync(response, "registration")) { return; } } }