示例#1
0
        public async Task <ResponseHitGameView> Hit(long playerId, long sessionId)
        {
            bool isLastAction = false;
            await _historyManager.Create(playerId,
                                         UserMessages.ChoseToHitMessage, sessionId);

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

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

            if (playerScore >= Constants.BlackjackValue)
            {
                isLastAction = true;
                await GiveCardsToDealer(sessionId);
            }

            ResponseHitGameView gameView = await _gameViewManager.GetHitGameView(playerId, sessionId, isLastAction);

            if (isLastAction)
            {
                await _sessionManager.Close(sessionId);
            }
            return(gameView);
        }
示例#2
0
        public static ResponseHitGameView GetHitGameView(long sessionId, Player dealer, Player player, IEnumerable <Player> bots)
        {
            var responseHitGameView = new ResponseHitGameView
            {
                Player    = GetPlayerHitGameViewItem(player),
                Dealer    = GetDealerHitGameViewItem(dealer),
                Bots      = GetPlayerHitGameViewItems(bots),
                SessionId = sessionId
            };

            return(responseHitGameView);
        }
示例#3
0
        public async Task <IHttpActionResult> Hit([FromBody] RequestHitGameView request)
        {
            try
            {
                ResponseHitGameView view = await _service.Hit(request.PlayerId, request.SessionId);

                return(Ok(view));
            }
            catch (Exception exception)
            {
                Log.Error(exception.ToString());
                return(InternalServerError(exception));
            }
        }
示例#4
0
        public async Task <ResponseHitGameView> GetHitGameView(long playerId, long sessionId, bool isLastAction)
        {
            (Player player, Player dealer, IEnumerable <Player> bots) = await _gameManager.GetAllGamePlayers(playerId, sessionId);

            ResponseHitGameView gameView = HitGameViewMapper.GetHitGameView(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 = HitGameViewMapper.GetHandHitGameViewItem(playerCards, playerScore);
            gameView.Dealer.Hand = HitGameViewMapper.GetHandHitGameViewItem(dealerCards, dealerScore);

            if (isLastAction)
            {
                (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);

                bot.Hand = HitGameViewMapper.GetHandHitGameViewItem(botCards, botScore);
                if (isLastAction)
                {
                    (int botGameState, string botGameResult) = _gameResultManager.GetGameStateResult(botScore, dealerScore);
                    bot.GameResult.State  = botGameState;
                    bot.GameResult.Result = botGameResult;
                }
            }

            return(gameView);
        }