예제 #1
0
 public bool TryTakeCard(out PlayingCard card)
 {
     if (deck.Count == 0)
     {
         card = null;
         return(false);
     }
     card = deck[deck.Count - 1];
     deck.RemoveAt(deck.Count - 1);
     return(true);
 }
예제 #2
0
 private static PlayingCard[] GenerateAllCards()
 {
     PlayingCard[] array = new PlayingCard[52];
     for (int i = 0; i < 4; i++)
     {
         for (int j = 0; j < 13; j++)
         {
             array[i * 13 + j] = new PlayingCard((Suit)i, (Rank)j);
         }
     }
     return(array);
 }
예제 #3
0
 public DeckOfCards()
 {
     deck = new List <PlayingCard>(52);
     for (int i = 0; i < 4; i++)
     {
         for (int j = 0; j < 13; j++)
         {
             deck.Add(PlayingCard.GetCard(i, j));
         }
     }
     ShuffleDeck();
 }
예제 #4
0
        public void ShuffleDeck()
        {
            int num = deck.Count;

            while (num > 1)
            {
                num--;
                int         index = Random.Range(0, num);
                PlayingCard value = deck[index];
                deck[index] = deck[num];
                deck[num]   = value;
            }
        }
예제 #5
0
 public void AddCard(PlayingCard card)
 {
     deck.Insert(0, card);
 }