private async Task DistributeFirstCards(IEnumerable <GamePlayer> gamePlayers) { List <Card> deck = (await _cardRepository.GetAll()).ToList(); deck = ShuffleDeck(deck); var playerCards = new List <PlayerCard>(); foreach (GamePlayer gamePlayer in gamePlayers) { gamePlayer.PlayerCards = new List <PlayerCard>(); PlayerCard firstCard = AddCardToPlayer(gamePlayer, deck); PlayerCard secondCard = AddCardToPlayer(gamePlayer, deck); playerCards.AddRange(gamePlayer.PlayerCards); } await _playerCardRepository.CreateMany(playerCards, ToStringHelper.GetTableName(typeof(PlayerCard))); }
private async Task DistributeCards(List <GamePlayer> players, int cardAmountPerPlayer, bool doesDealerNeedCards = true) { var createdPlayerCards = new List <PlayerCard>(); int cardAmount = players.Count() * cardAmountPerPlayer; List <Card> deck = await _cardRepository.GetSpecifiedAmount(cardAmount); foreach (GamePlayer player in players) { if (doesDealerNeedCards || player.Player.Type != PlayerType.Dealer) { List <Card> cards = PopCardsFromDeck(deck, cardAmountPerPlayer); List <PlayerCard> createdPlayerCardsForPlayer = CustomMapper.MapPlayerCards(player, cards); player.PlayerCards.AddRange(createdPlayerCardsForPlayer); createdPlayerCards.AddRange(createdPlayerCardsForPlayer); } } await _playerCardRepository.CreateMany(createdPlayerCards); }