public async Task <GameBoardDto> GetGameBoardByRound(int roundId) { try { var MyGameBoard = new GameBoardDto() { RoundId = roundId, Categories = new List <CategoryDto>() }; //get random categories by round id where count > 5 var SelectedCats = await _repo.GetCategoriesByRound(roundId); MyGameBoard.Categories.AddRange(SelectedCats); foreach (var cat in MyGameBoard.Categories) { cat.Questions = new List <QuestionDto>(); var CategoryQuestions = await _repo.GetQuestionsByCategory(cat.CategoryId); cat.Questions.AddRange(CategoryQuestions); } return(MyGameBoard); } catch (Exception ex) { throw ex; } }
private async void DoWork(object obj, EventArgs args) { try { GameBoardDto gameBoardDto = await GetGameBoard(); ProcessResponse(gameBoardDto); } catch (Exception ex) { GameException = "Не удалось обработать запрос"; this.logger.Error(ex, $"Не удалось обработать запрос"); } }
private async Task InitializeGame() { try { GameBoardDto gameBoardDto = await GetGameBoard(); this.GameBoardSize.Height = ParseCoordinate(gameBoardDto.GameBoardSize.Height); this.GameBoardSize.Width = ParseCoordinate(gameBoardDto.GameBoardSize.Width); _timer = new DispatcherTimer(DispatcherPriority.Send); _timer.Tick += DoWork; _timer.Interval = TimeSpan.FromMilliseconds(gameBoardDto.TimeUntilNextTurnMilliseconds / 10); _timer.Start(); this.logger.Info("Игра инициализирована"); } catch (Exception ex) { GameException = "Не удалось инициализировать игру"; this.logger.Error(ex, "Не удалось инициализировать игру"); } }
public IActionResult GetGameboard() { try { GameBoardDto gameBoard = new GameBoardDto { TurnNumber = this.gameService.Game.TurnNumber, TimeUntilNextTurnMilliseconds = this.gameService.Game.GameBoardSettings.TimeUntilNextTurnMilliseconds, GameBoardSize = this.gameService.Game.GameBoardSettings.GameBoardSize, Food = this.gameService.Game.Food, Snake = this.gameService.Game.Snake }; this.logger.LogInformation($"Отправляем ответ: {JsonSerializer.Serialize(gameBoard)}"); return(Ok(gameBoard)); } catch (Exception ex) { this.logger.LogError(ex, "Ошибка при обработке запроса"); return(StatusCode(500, "Ошибка при обработке запроса")); } }
private void ProcessResponse(GameBoardDto gameBoardDto) { Snake.Clear(); foreach (Point point in gameBoardDto.Snake) { ViewPoint processPoint = new ViewPoint(ParseCoordinate(point.X), ParseCoordinate(point.Y), rectangleSize, margin); Snake.Add(processPoint); } Food.Clear(); foreach (Point point in gameBoardDto.Food) { ViewPoint processPoint = new ViewPoint(ParseCoordinate(point.X), ParseCoordinate(point.Y), rectangleSize, margin); Food.Add(processPoint); } GameException = String.Empty; }