예제 #1
0
        } // end method GetCard

        /// <summary>Shuffle method</summary>
        public void Shuffle()
        {
            Random random   = new Random();
            Cards  tempDeck = new Cards();

            bool[] arrayBooleans = new bool[TotalCards];

            for (int i = 0; i < TotalCards; i++)
            {
                int  randomCard = 0;
                bool uniqueCard = false;

                while (uniqueCard == false)
                {
                    randomCard = random.Next(TotalCards);
                    if (arrayBooleans[randomCard] == false)
                    {
                        uniqueCard = true;
                    }
                }

                arrayBooleans[randomCard] = true;
                tempDeck.Add(cards[randomCard]);
            }
            // copy entire tempDeck into cards
            tempDeck.CopyTo(cards);
        } // end method Shuffle
예제 #2
0
        public void Shuffle()
        {
            Cards newDeck = new Cards();

            bool[] assigned  = new bool[cards.Count];
            Random sourceGen = new Random();

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