public async Task <ResponseGameProcessGameView> StartGame(RequestGameStartOptionsGameView viewModel) { long playerId = await CheckPLayerName(viewModel.PlayerName) ? await CreatePlayerAndReturnId(viewModel) : await _playerRepository.GetPlayerIdByPlayerName(viewModel.PlayerName); long gameId = await CreateGameAndReturnId(viewModel, playerId); long roundId = await CreateRoundAndReturnId(gameId); Player player = await _playerRepository.Get(playerId); Player dealer = await _playerRepository.GetFirstPlayerByRole(PlayerRole.Dealer); List <Player> botList = await _playerRepository.GetQuantityByRole(viewModel.BotsAmount, (int)PlayerRole.Bot); var playerList = new List <Player>(); playerList.Add(player); playerList.AddRange(botList); playerList.Add(dealer); List <PlayerRoundHand> playerRoundHandList = CreatePlayerRoundHands(playerList, roundId); await _playerRoundHandRepository.CreateManyAsync(playerRoundHandList); playerRoundHandList = await _playerRoundHandRepository.GetPLayerRoundHandListByRoundId(roundId); var gameViewModel = new ResponseGameProcessGameView(); gameViewModel.Game = _maping.MapGameToGameGameProcessGameViewItem(await _gameRepository.Get(gameId)); gameViewModel.Round = _maping.MapRoundToRoundGameProcessGameViewItem(await _roundRepository.Get(roundId)); gameViewModel.Player = _maping.MapPlayerToPlayerGameProccessGameViewItem(playerList.Where(x => x.Role == PlayerRole.Player).FirstOrDefault(), playerRoundHandList); gameViewModel.Dealer = _maping.MapPlayerToPlayerGameProccessGameViewItem(playerList.Where(x => x.Role == PlayerRole.Dealer).FirstOrDefault(), playerRoundHandList); gameViewModel.Bots = _maping.MapPlayerListToPlayerGameProccessGameViewItem(playerList.Where(x => x.Role == PlayerRole.Bot).ToList(), playerRoundHandList); return(gameViewModel); }
private async Task <long> CreatePlayerAndReturnId(RequestGameStartOptionsGameView playerHistoryViewModel) { Player player = new Player(); player.Name = playerHistoryViewModel.PlayerName; player.Role = PlayerRole.Player; long Id = await _playerRepository.CreateAndReturnId(player); return(Id); }
private async Task <long> CreateGameAndReturnId(RequestGameStartOptionsGameView playerHistoryViewModel, long playerId) { Game game = new Game(); game.PlayerId = playerId; game.PlayersAmount = playerHistoryViewModel.BotsAmount + 1; game.GameNumber = await _gameRepository.GetNewGameNumber(playerId); long Id = await _gameRepository.CreateAndReturnId(game); return(Id); }
public async Task <ResponseGameProcessGameView> GameStartOptions(RequestGameStartOptionsGameView item) { ResponseGameProcessGameView startData = await _gameService.StartGame(item); return(startData); }