Exemple #1
0
 public Deck()
 {
     for (CardSuit s = CardSuit.Club; s <= CardSuit.Spade; s++)
     {
         for (CardRank r = CardRank.Two; r <= CardRank.Ace; r++)
         {
             PlayingCard card = new PlayingCard(r, s);
             card.Points = AssignPoints(card.Rank);
             deck.Add(card);
         }
     }
 }
Exemple #2
0
 public void Shuffle()
 {
     for (int i = deck.Count - 1; i > 1; i--)
     {
         //find a random number in the front of the last card in deck
         int pos = rnd.Next(i);
         //make a reference to the last card in the deck
         PlayingCard tmp = deck[i];
         //swap the two Card objects at the positions pos and i
         deck[i]   = deck[pos];
         deck[pos] = tmp;
     }
 }
Exemple #3
0
 public PlayingCard DealTopCard()
 {
     if (!IsEmpty())
     {
         PlayingCard c = deck[0];
         deck.RemoveAt(0);
         return(c);
     }
     else
     {
         return(null);
     }
 }
Exemple #4
0
 public Deck(params CardRank[] ranks)
 {
     for (CardSuit s = CardSuit.Club; s <= CardSuit.Spade; s++)
     {
         for (CardRank r = CardRank.Two; r <= CardRank.Ace; r++)
         {
             if (ranks.Length == 0 || ranks.Contains(r))
             {
                 PlayingCard card = new PlayingCard(r, s);
                 deck.Add(card);
             }
         }
     }
 }