// Start public async Task <StartGameResponseViewItem> CreateStartGameModel(Player user, string gameId, List <Player> botPlayerList, int cardLeft) { List <CardMove> moveList = await _cardMoveRepository.GetByGameId(gameId); PlayerStartGameViewItem player = StartPlayerMapper(user, moveList); List <PlayerStartGameViewItem> botMoveList = StartGetBots(botPlayerList, moveList); var model = CreateStartModel(gameId, player, botMoveList, cardLeft); return(model); }
public async Task <GetGameStatisticViewItem> GetGame(string gameId, string userName) { if ( (userName == null && gameId == null) || (userName != null && gameId == null) || (userName == null && gameId != null)) { throw new BadRequestException(); } Player user = await _playerRepository.GetByUserName(userName); List <Player> botList = await GetBotsFromGame(user.Id, gameId); List <CardMove> moveList = await _cardMoveRepository.GetByGameId(gameId); var userModel = await CreatePlayer(user, moveList); var botsModel = await GetBots(botList, moveList); var win = await _gameUsersRepository.GetWinnerByGameId(gameId); var winner = await _playerRepository.Get(win.UserId); var response = new GetGameStatisticViewItem { GameId = gameId, User = userModel, Bots = botsModel, Winner = winner.UserName }; return(response); }
private async Task <List <Winner> > SearchWinner(string gameId) { var cardMoveList = await _cardMoveRepository.GetByGameId(gameId); if (cardMoveList == null) { throw new NotFoundException(); } var playersCount = cardMoveList .GroupBy(r => r.PlayerId) .Select(x => GetWinners(x.Key, x.Sum(f => f.Value)).Result) .OrderBy(t => t.Value) .ToList(); var winnersList = new List <Winner>(); var winners = playersCount .Where(x => x.Value < 22) .MaxBy(z => z.Value) .ToList(); winnersList.AddRange(winners); foreach (var winner in winners) { GameUser player = await _gameUsersRepository.GetFutureWinnerByPlayerIdAndGameId(winner.PlayerId, gameId); if (player == null) { throw new NotFoundException(); } player.Winner = true; await _gameUsersRepository.UpdateWinner(player); } return(winnersList); }