Esempio n. 1
0
        public async Task <ResponseGetDeallerExtraCardGameView> GetDeallerExtraCard(RequestGetDeallerExtraCardGameView requestGetDeallerExtraCardGameView)
        {
            Hand hand = await _handRepository.GetWithCards(requestGetDeallerExtraCardGameView.HandId);

            if (hand == null)
            {
                var stringBuilder = new StringBuilder();

                stringBuilder.AppendLine(string.Format("GameId: {0}", requestGetDeallerExtraCardGameView.GameId));
                stringBuilder.AppendLine(string.Format("HandId: {0}", requestGetDeallerExtraCardGameView.HandId));
                stringBuilder.AppendLine(string.Format("Message: {0}", SolutionConstants.BUSINESS_LOGIC_GET_ITEM_EXCEPTION_MESSAGE));

                string message = stringBuilder.ToString();

                throw new BusinessLogicGetItemException(message);
            }

            int playerPoints = hand.Summary;

            var extraCards = new List <ResponseGetDeallerExtraCardGameViewItem>();

            var responseView = new ResponseGetDeallerExtraCardGameView();

            if (playerPoints >= GameConstants.DESIRED_SUMM_CARDS_BOT_AND_DEALLER)
            {
                responseView.ExtraCards = extraCards;

                return(responseView);
            }

            RequestGetExtraCardGameView requestGetExtraCardView = _mapper.Map <RequestGetDeallerExtraCardGameView, RequestGetExtraCardGameView>(requestGetDeallerExtraCardGameView);

            for (int i = playerPoints; i < GameConstants.DESIRED_SUMM_CARDS_BOT_AND_DEALLER;)
            {
                ResponseGetExtraCardGameView extraCardView = await GetExtraCard(requestGetExtraCardView);

                ResponseGetDeallerExtraCardGameViewItem extraCardViewItem = _mapper.Map <ResponseGetExtraCardGameView, ResponseGetDeallerExtraCardGameViewItem>(extraCardView);

                extraCards.Add(extraCardViewItem);

                hand = await _handRepository.GetWithCards(hand.Id);

                i = _gameUtility.CalculateCardsSumm(hand.HandCards.Select(item => item.Card).ToList());
            }

            responseView.ExtraCards = extraCards;

            return(responseView);
        }
Esempio n. 2
0
        public async Task <ResponseGetDeallerExtraCardGameView> GetDeallerExtraCard([FromBody] RequestGetDeallerExtraCardGameView getDeallerExtraCardView)
        {
            ResponseGetDeallerExtraCardGameView responseGetDeallerExtraCardView = await _gameLogicService.GetDeallerExtraCard(getDeallerExtraCardView);

            return(responseGetDeallerExtraCardView);
        }