Exemplo n.º 1
0
        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);
        }
        public async Task <DetailsRoundHistoryView> GetRoundsDetailsByRoundId(int roundId)
        {
            Round round = await _roundRepository.Get(roundId);

            Game game = await _gameRepository.Get(round.GameId);

            Player player = await _playerRepository.Get(game.PlayerId);

            Player dealer = await _playerRepository.GetFirstPlayerByRole(PlayerRole.Dealer);

            List <Player> bots = await _playerRepository.GetQuantityByRole(game.PlayersAmount - 1, (int)PlayerRole.Bot);

            var players = new List <Player>();

            players.Add(player);
            players.Add(dealer);
            players.AddRange(bots);

            List <PlayerRoundHand> hands = await _playerRoundHandRepository.GetPLayerRoundHandListByRoundId(round.Id);

            var playerRoundHandId = new List <long>();

            foreach (var hand in hands)
            {
                playerRoundHandId.Add(hand.Id);
            }

            List <Card> cards = await _cardRepository.GetPlayerRoundHandCards(playerRoundHandId);

            var data = new DetailsRoundHistoryView();

            data.Players = _maping.MapPlayersToPlayerDetailsRoundHistoryViewItem(players, hands, cards);
            return(data);
        }