Ejemplo n.º 1
0
 public void ShuffleDeck()
 {
     // to shuffle a deck, assign the next random number sequentially to the deck.
     // don't just do random of 52 cards, but other to prevent duplicate numbers
     // from possibly coming in
     foreach (var oneCard in SingleDeck)
     {
         oneCard.RndNumber = rndGen.Next(3901);              // any number could be used...
     }
     // great, now every card has a randomized number assigned.
     // return the list sorted by that random number...
     ShuffledDeck = SingleDeck.OrderBy(o => o.RndNumber).ToList();
 }
Ejemplo n.º 2
0
    public DeckOfCards()
    {
        // build the deck of cards once...
        // Start going through each suit
        foreach (CardSuit s in typeof(CardSuit).GetEnumValues())
        {
            // now go through each card within each suit
            foreach (CardFace f in typeof(CardFace).GetEnumValues())
            {
                // Now, add a card to the deck of the suite / face card
                SingleDeck.Add(new SingleCard {
                    Face = f, Suit = s
                });
            }
        }

        // so now you have a master list of all cards in your deck declared once...
    }