Exemple #1
0
        public void Shuffle()
        {
            //Card[] newDeck = new Card[52];
            CardsCollection newDeck = new CardsCollection();

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

            for (int i = 0; i < 52; i++)
            {
                //int destCard = 0;
                int  sourceCard = 0;
                bool foundCard  = false;
                while (foundCard == false)
                {
                    sourceCard = sourceGen.Next(52);//Next(x)----生成一个介于0~x之间的随机数。
                    if (assigned[sourceCard] == false)
                    {
                        foundCard = true;
                    }
                }
                assigned[sourceCard] = true;
                //newDeck[destCard] = cards[i];
                newDeck.Add(cards[sourceCard]);
            }
            newDeck.CopyTo(cards);
        }
Exemple #2
0
 /*public void Add(Card newCard)
  * {
  *  List.Add(newCard);
  * }
  * public void Remove(Card oldCard)
  * {
  *  List.Remove(oldCard);
  * }
  * public Card this[int cardIndex]
  * {
  *  get{ return (Card)List[cardIndex]; }
  *  set { List[cardIndex] = value; }
  * }*/
 public void CopyTo(CardsCollection targetCards)
 {
     for (int index = 0; index < this.Count; index++)
     {
         targetCards[index] = this[index];
     }
 }
Exemple #3
0
        public object Clone()
        {
            CardsCollection newCards = new CardsCollection();

            foreach (Card sourceCard in this)
            {
                newCards.Add((Card)sourceCard.Clone());
            }
            return(newCards);
        }
Exemple #4
0
 private Deck(CardsCollection newCards)
 {
     cards = newCards;
 }