예제 #1
0
        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);
        }