public async Task <ResponseGetPlayersTwoCardsGameView> GetPlayersTwoCards(RequestGetPlayersTwoCardsGameView requestGetPlayersTwoCardsGameView) { Round round = await _roundRepository.Get(requestGetPlayersTwoCardsGameView.RoundId); Game game = await _gameRepository.GetGameWithPlayerGames(round.GameId); if (round == null || game == null) { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine(string.Format("RoundId: {0}", requestGetPlayersTwoCardsGameView.RoundId.ToString())); for (int i = 0; i < requestGetPlayersTwoCardsGameView.Players.Count; i++) { stringBuilder.AppendLine(string.Format("PlayerId: {0}", requestGetPlayersTwoCardsGameView.Players[i])); } stringBuilder.AppendLine(string.Format("Message: {0}", SolutionConstants.BUSINESS_LOGIC_GET_ITEM_EXCEPTION_MESSAGE)); string message = stringBuilder.ToString(); throw new BusinessLogicGetItemException(message); } await GiveOutTwoCards(game.Id, requestGetPlayersTwoCardsGameView); List <Hand> listHands = await _handRepository.GetListHandsWithCardsWithoutDeallerHandByRoundId(round.Id); if (listHands == null) { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine(string.Format("RoundId: {0}", round.Id)); stringBuilder.AppendLine(string.Format("Message: {0}", SolutionConstants.BUSINESS_LOGIC_GET_ITEM_EXCEPTION_MESSAGE)); string message = stringBuilder.ToString(); throw new BusinessLogicGetItemException(message); } var responseView = new ResponseGetPlayersTwoCardsGameView(); for (int i = 0; i < listHands.Count; i++) { List <Card> cards = listHands[i].HandCards.Select(item => item.Card).ToList(); var responseViewItem = new GetPlayersTwoCardsGameViewItem(); responseViewItem.PlayerId = listHands[i].PlayerId; responseViewItem.HandId = listHands[i].Id; responseViewItem.Cards = _mapper.Map <List <Card>, List <CardGetPlayersTwoCardsGameViewItemItem> >(cards); responseViewItem.Summary = listHands[i].Summary; responseView.ListPlayersWithCards.Add(responseViewItem); } return(responseView); }
private async Task GiveOutTwoCards(int gameId, RequestGetPlayersTwoCardsGameView requestView) { Deck infinityDeck = await _deckProvider.GetAllDeckFromCache(gameId); var hands = new List <Hand>(); var handCards = new List <HandCard>(); for (int i = 0; i < requestView.Players.Count; i++) { Hand hand = await _handRepository.GetHandByRoundAndPlayerId(requestView.RoundId, requestView.Players[i]); if (hand == null) { continue; } int summary = 0; var cards = new List <Card>(); for (int y = 0; y < GameConstants.TWO_CARDS; y++) { Card card = DeckExtension.GetCard(infinityDeck); cards.Add(card); var handCard = new HandCard(); handCard.CardId = card.Id; handCard.HandId = hand.Id; handCards.Add(handCard); summary += _gameUtility.GetCardValue(card.Face); } hand.Summary = summary; hand.VictoryType = _gameUtility.CheckTypeOfVictory(cards); if (hand.VictoryType == VictoryType.GoldenPoint) { hand.Summary = GameConstants.BLACKJACK; } hands.Add(hand); } await _handRepository.UpdateMultiple(hands); await _handCardRepository.CreateMultiple(handCards); _deckProvider.SetDeckInMemoryCashe(gameId, infinityDeck); }
public async Task <ResponseGetPlayersTwoCardsGameView> GetPlayersTwoCards([FromBody] RequestGetPlayersTwoCardsGameView requestGetPlayersTwoCardsGameView) { ResponseGetPlayersTwoCardsGameView responseGetPlayersTwoCardsGameView = await _gameLogicService.GetPlayersTwoCards(requestGetPlayersTwoCardsGameView); return(responseGetPlayersTwoCardsGameView); }