コード例 #1
0
        /// <summary>
        /// swaps each card at an index with a random card, 5 times.
        /// </summary>
        public void Shuffle()
        {
            CardCollection randomDeck = new CardCollection();
            Random         randSource = new Random();
            int            randIndex;
            PlayingCard    tempCardHolder;

            for (int j = 0; j < 5; j++)
            {
                for (int i = 0; i < SIZE_OF_DECK; i++)
                {
                    // Random index for each position
                    randIndex = i + randSource.Next(SIZE_OF_DECK - i);

                    // swap the cards
                    tempCardHolder   = cards[randIndex];
                    cards[randIndex] = cards[i];
                    cards[i]         = tempCardHolder;
                }
            }
            // copy the random deck to this deck
            randomDeck.CopyTo(cards);
        }
コード例 #2
0
 /// <summary>
 /// Creates a deck for deep cloning
 /// </summary>
 /// <param name="newCards">The new cards</param>
 private Deck(CardCollection newCards)
 {
     cards = newCards;
 }