Пример #1
0
        public void Shuffle()
        {//http://rosettacode.org/wiki/Knuth_shuffle
            Random r = new Random();

            for (int i = 0; i < deck.Length; i++)
            {
                int         j    = r.Next(i, deck.Length);
                PlayingCard temp = deck[i];
                deck[i] = deck[j];
                deck[j] = temp;
            }
        }
Пример #2
0
        public void Shuffle()
        {//http://rosettacode.org/wiki/Knuth_shuffle
            Random r = new Random();

            for (int i = 0; i < topIndex; i++)
            {
                int         j    = r.Next(i, topIndex + 1);
                PlayingCard temp = hand[i];
                hand[i] = hand[j];
                hand[j] = temp;
            }
        }
Пример #3
0
        public CardDeck()
        {//Constructs a deck.
            topIndex = deck.Length - 1;
            int count = 0;

            for (int i = 1; i < 5; i++)
            {
                for (int j = 1; j < 14; j++)
                {
                    deck[count] = new PlayingCard(j, i, false);
                    count++;
                }
            }
            deck[count] = new PlayingCard(0, 5, false);
        }
Пример #4
0
 public PlayingCard PickCardAt(int i)
 {//Picks a card from the player's hand and returns the card picked.
     if (i >= 0 && i <= topIndex)
     {
         PlayingCard temp = hand[i];
         hand[i]        = hand[topIndex];
         hand[topIndex] = null;
         topIndex--;
         return(temp);
     }
     else
     {
         throw new IndexOutOfRangeException("Your choice is not in the range of valid numbers");
     }
 }
Пример #5
0
        public void AddCard(PlayingCard card)
        {//Adds a card to the player's hand after selecting it from another player.
            bool duplicate = false;

            for (int i = 0; i <= topIndex; i++)
            {
                if (hand[i] != null && card != null)
                {
                    if (hand[i].Rank == card.Rank)
                    {
                        if (topIndex == i)
                        {//If duplicate is final card in hand.
                            CardDeck.ReturnCard(hand[topIndex]);
                            CardDeck.ReturnCard(card);
                            hand[topIndex] = null;
                            topIndex--;
                        }
                        else
                        {//If dupicate is not final card in hand.
                            CardDeck.ReturnCard(hand[i]);
                            CardDeck.ReturnCard(card);
                            hand[i]        = hand[topIndex];
                            hand[topIndex] = null;
                            topIndex--;
                        }
                        duplicate = true;
                        break;
                    }
                }
            }
            if (!duplicate)
            {//Adds the card if a duplicate is not found.
                topIndex++;
                hand[topIndex] = card;
            }
        }
Пример #6
0
 public override void Deal(PlayingCard card)
 {
     card.FaceUp = true;
     topIndex++;
     Hand[topIndex] = card;
 }
Пример #7
0
 public static void ReturnCard(PlayingCard card)
 {//Returns the card to the deck.
     topIndex++;
     deck[topIndex] = card;
 }
Пример #8
0
 public virtual void Deal(PlayingCard card)
 {
 }