Exemplo n.º 1
0
 public void ResetDeck()
 {
     _LastDrawnCard = null;
     if (UseDiscardStack)
     {
         DrawStack.AddCards(true, DiscardStack.RemoveAllCards());
     }
     else
     {
         DrawStack.AddCards(true);
     }
 }
Exemplo n.º 2
0
 public void Enqueue(PlayingCard card)
 {
     if (BottomCard != null)
     {
         BottomCard.Next = card;
     }
     else
     {
         TopCard = card;
     }
     BottomCard = card;
     TotalCards++;
 }
Exemplo n.º 3
0
 public string DrawString()
 {
     _LastDrawnCard = DrawStack.Dequeue(!UseDiscardStack);
     if (_LastDrawnCard != null)
     {
         if (UseDiscardStack)
         {
             DiscardStack.Enqueue(_LastDrawnCard);
         }
         return(_LastDrawnCard.Value.ToString() + "_" + _LastDrawnCard.Suit.ToString());
     }
     return(null);
 }
Exemplo n.º 4
0
 public PlayingCard Draw()
 {
     lock (this)
     {
         _LastDrawnCard = DrawStack.Dequeue(!UseDiscardStack);
         if (_LastDrawnCard != null)
         {
             if (UseDiscardStack)
             {
                 DiscardStack.Enqueue(_LastDrawnCard);
             }
             return(_LastDrawnCard);
         }
         return(null);
     }
 }
Exemplo n.º 5
0
 public PlayingCard Dequeue(bool enqueueImmediately)
 {
     if (TopCard != null)
     {
         PlayingCard card = new PlayingCard(TopCard);
         TopCard = TopCard.Next;
         TotalCards--;
         if (enqueueImmediately)
         {
             Enqueue(card);
         }
         return(card);
     }
     else
     {
         BottomCard = null;
     }
     return(null);
 }
Exemplo n.º 6
0
 /* Richard Durstenfeld version of Fisher–Yates shuffle
  * -- To shuffle an array a of n elements (indices 0..n-1):
  *  for i from n−1 downto 1 do
  *  j ← random integer such that 0 ≤ j ≤ i
  *  exchange a[j] and a[i]
  */
 void Shuffle()
 {
     if (TotalCards > 1)
     {
         var         cardsArray = RemoveAllCards();
         PlayingCard tempCard   = null;
         for (int index = cardsArray.Length - 1; index > 0; index--)
         {
             int random = Random.Next(0, index + 1);
             if (index != random)
             {
                 tempCard           = cardsArray[index];
                 cardsArray[index]  = cardsArray[random];
                 cardsArray[random] = tempCard;
             }
         }
         foreach (var card in cardsArray)
         {
             Enqueue(card);
         }
     }
 }
Exemplo n.º 7
0
        public string[] DrawStrings(int consecutiveDraws)
        {
            List <string> cardList = new List <string>();

            for (int draw = 0; draw < consecutiveDraws; draw++)
            {
                _LastDrawnCard = DrawStack.Dequeue(!UseDiscardStack);
                if (_LastDrawnCard != null)
                {
                    if (UseDiscardStack)
                    {
                        DiscardStack.Enqueue(_LastDrawnCard);
                    }
                    cardList.Add(_LastDrawnCard.Value.ToString() + "_" + _LastDrawnCard.Suit.ToString());
                }
            }
            if (cardList.Count > 0)
            {
                return(cardList.ToArray());
            }
            return(null);
        }
Exemplo n.º 8
0
        public PlayingCard[] Draw(int consecutiveDraws)
        {
            List <PlayingCard> cardList = new List <PlayingCard>();

            for (int draw = 0; draw < consecutiveDraws; draw++)
            {
                _LastDrawnCard = DrawStack.Dequeue(!UseDiscardStack);
                if (_LastDrawnCard != null)
                {
                    if (UseDiscardStack)
                    {
                        DiscardStack.Enqueue(_LastDrawnCard);
                    }
                    cardList.Add(_LastDrawnCard);
                }
            }
            if (cardList.Count > 0)
            {
                return(cardList.ToArray());
            }
            return(null);
        }
Exemplo n.º 9
0
 public PlayingCard(PlayingCard copy)
 {
     _Value = copy.Value;
     _Suit  = copy.Suit;
 }