Пример #1
0
        public static Deck MakeRandomDeck(ICardCollection cardCollection, GameRules gameRules, int deckSize, Random random)
        {
            var cards = cardCollection.GetCards().ToList();

            if (deckSize < gameRules.MinDeckSize || deckSize > gameRules.MaxDeckSize)
            {
                throw new ArgumentException("Deck size is incorrect");
            }
            var deck = new Deck(gameRules);

            while (deck.Count < deckSize)
            {
                var card = random.ChoiceOrDefault(cards.Where(x => deck.CanAddCard(x)));
                if (card == null)
                {
                    throw new ArgumentException("Collection is not large enough");
                }
                deck.Add(card);
            }
            return(deck);
        }