public object Clone() { CardCollection newCards = new CardCollection(); foreach (Card sourceCard in List) { newCards.Add((Card)sourceCard.Clone()); } return(newCards); }
public Deck() { // Line of code removed here for (int suitVal = 0; suitVal < 4; suitVal++) { for (int rankVal = 1; rankVal < 14; rankVal++) { cards.Add(new Card((Suit)suitVal, (Rank)rankVal)); } } }
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); }