コード例 #1
0
ファイル: Deck.cs プロジェクト: anasteyshank/Durak
        /// <summary>
        /// The method that shuffles the cards in the deck
        /// </summary>
        public void Shuffle()
        {
            Cards newDeck = new Cards();              // temporary collection of cards

            bool[] assigned  = new bool[cards.Count]; // indicates if the spot is taken by the card
            Random sourceGen = new Random();          // generates a random number

            // Loop through the deck of cards
            for (int i = 0; i < cards.Count; i++)
            {
                int  sourceCard = 0;      // index of the destination card
                bool foundCard  = false;  // indicates if the spot was found
                // while the card isn't found
                while (!foundCard)
                {
                    sourceCard = sourceGen.Next(cards.Count);  // generate a random number from 1 to 52
                    // if the spot is found, quit the loop
                    if (assigned[sourceCard] == false)
                    {
                        foundCard = true;
                    }
                }
                // add the card to the temporary collection
                assigned[sourceCard] = true;
                newDeck.Add(cards[sourceCard]);
            }
            // set the original array to the new one
            newDeck.CopyTo(cards);
        }
コード例 #2
0
        public void Shuffle()
        {
            Cards newCards = new Cards();

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

            for (int i = 0; i < 52; i++)
            {
                int  foundCard = 1;
                bool founded   = false;
                while (!founded)
                {
                    foundCard = itemRandom.Next(52);
                    if (!assigned[foundCard])
                    {
                        founded = true;
                    }
                }
                newCards.AddCard(_cards[foundCard]);
                assigned[foundCard] = true;
            }

            newCards.CopyTo(_cards, 0);
        }
コード例 #3
0
        public void Shuffle()
        {
            Cards newDeck = new Cards();

            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);
        }
コード例 #4
0
ファイル: Deck.cs プロジェクト: vladasp/traineeship
 public void Shuffle()
 {
     Cards newDeck = new Cards();
     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);
 }