Ejemplo n.º 1
0
        public async Task <ResponseDoubleGameView> GetDoubleGameView(long playerId, long sessionId)
        {
            (Player player, Player dealer, IEnumerable <Player> bots) = await _gameManager.GetAllGamePlayers(playerId, sessionId);

            ResponseDoubleGameView gameView = DoubleGameViewMapper.GetDoubleGameView(sessionId, dealer, player, bots);

            IEnumerable <Card> playerCards = await _gameManager.GetCards(player.Id, sessionId);

            IEnumerable <Card> dealerCards = await _gameManager.GetCards(dealer.Id, sessionId);

            int playerScore = await _gameManager.GetHandScore(player.Id, sessionId);

            int dealerScore = await _gameManager.GetHandScore(dealer.Id, sessionId);

            gameView.Player.Hand = DoubleGameViewMapper.GetHandDoubleGameViewItem(playerCards, playerScore);
            gameView.Dealer.Hand = DoubleGameViewMapper.GetHandDoubleGameViewItem(dealerCards, dealerScore);

            (int playerGameState, string playerGameResult) = _gameResultManager.GetGameStateResult(playerScore, dealerScore);
            gameView.Player.GameResult.State  = playerGameState;
            gameView.Player.GameResult.Result = playerGameResult;

            foreach (var bot in gameView.Bots)
            {
                IEnumerable <Card> botCards = await _gameManager.GetCards(bot.Id, sessionId);

                int botScore = await _gameManager.GetHandScore(bot.Id, sessionId);

                (int botGameState, string botGameResult) = _gameResultManager.GetGameStateResult(botScore, dealerScore);
                bot.Hand              = DoubleGameViewMapper.GetHandDoubleGameViewItem(botCards, botScore);
                bot.GameResult.State  = botGameState;
                bot.GameResult.Result = botGameResult;
            }

            return(gameView);
        }
Ejemplo n.º 2
0
        public static ResponseDoubleGameView GetDoubleGameView(long sessionId, Player dealer, Player player, IEnumerable <Player> bots)
        {
            var responseDoubleGameView = new ResponseDoubleGameView
            {
                Player    = GetPlayerDoubleGameViewItem(player),
                Dealer    = GetDealerDoubleGameViewItem(dealer),
                Bots      = GetPlayerDoubleGameViewItems(bots),
                SessionId = sessionId
            };

            return(responseDoubleGameView);
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> Double([FromBody] RequestDoubleGameView request)
        {
            try
            {
                ResponseDoubleGameView view = await _service.Double(request.PlayerId, request.SessionId);

                return(Ok(view));
            }
            catch (Exception exception)
            {
                Log.Error(exception.Message);
                return(InternalServerError(exception));
            }
        }
Ejemplo n.º 4
0
        public async Task <ResponseDoubleGameView> Double(long playerId, long sessionId)
        {
            await _historyManager.Create(playerId,
                                         UserMessages.ChoseToDoubleMessage, sessionId);

            await GiveCards(1, playerId, sessionId);
            await GiveCardsToBots(sessionId);
            await GiveCardsToDealer(sessionId);

            ResponseDoubleGameView gameView = await _gameViewManager.GetDoubleGameView(playerId, sessionId);

            await _sessionManager.Close(sessionId);

            return(gameView);
        }