private HandViewItem GetHand(List <Card> cardsInHand) { var hand = new HandViewItem { CardsInHand = new List <CardViewItem>() }; if (cardsInHand == null) { return(hand); } foreach (var cardInHand in cardsInHand) { hand.CardsInHand.Add(Mapper.Map <Card, CardViewItem>(cardInHand)); hand.CardsInHandValue += cardInHand.Value; } foreach (var card in hand.CardsInHand) { if ((card.Title.Replace(" ", string.Empty) == Constant.AceCardTitle) && (hand.CardsInHandValue > Constant.WinValue)) { hand.CardsInHandValue -= Constant.ImageCardValue; } } return(hand); }
private async Task <HandViewItem> GetPlayerHand(long playerId, long gameId) { var hand = new HandViewItem { CardsInHand = new List <CardViewItem>() }; List <long> cardsIdInPlayersHand = await _cardInHandRepository.GetCardsIdByPlayerIdAndGameId(playerId, gameId); var cards = await _cardRepository.GetByIds(cardsIdInPlayersHand); hand.CardsInHand = Mapper.Map <List <Card>, List <CardViewItem> >(cards); hand.CardsInHandValue = CalculateCardsValue(hand.CardsInHand); return(hand); }
private async Task <bool> BotTurn(long botId, List <Card> deck, long gameId, HandViewItem hand) { if (hand.CardsInHandValue >= Constant.ValueToStopDraw) { await AddMultipleCardsInHand(botId, hand.CardsInHand, gameId); return(false); } var card = Mapper.Map <Card, CardViewItem>(deck[0]); _logger.Log(LogHelper.GetEvent(botId, gameId, UserMessages.PlayerDrawCard(deck[0].Id))); deck.Remove(deck[0]); hand.CardsInHand.Add(card); hand.CardsInHandValue = CalculateCardsValue(hand.CardsInHand); return(await BotTurn(botId, deck, gameId, hand)); }