Beispiel #1
0
 public Deck()
 {
     for (int suitVal = 0; suitVal < 4; suitVal++)
     {
         for (int rankVal = 1; rankVal < 14; rankVal++)
         {
             cards.Add(new Card((Suit)suitVal, (Rank)rankVal));
         }
     }
 }
Beispiel #2
0
        public object Clone()
        {
            CardCollection newCards = new CardCollection();

            foreach (Card sourceCard in List)
            {
                newCards.Add((Card)sourceCard.Clone());
            }
            return(newCards);
        }
Beispiel #3
0
        public void Shuffle()
        {
            CardCollection newDeck = new CardCollection();

            bool[] assigned  = new bool[52];
            Random sourceGen = new Random();

            for (int i = 0; i < 52; i++)
            {
                int  sourceCard = 0;
                bool foundCard  = false;
                while (foundCard == false)
                {
                    sourceCard = sourceGen.Next(52);
                    if (assigned[sourceCard] == false)
                    {
                        foundCard = true;
                    }
                }
                assigned[sourceCard] = true;
                newDeck.Add(cards[sourceCard]);
            }
            newDeck.CopyTo(cards);
        }