Exemplo n.º 1
0
 /// <summary>
 /// Append a deck to the bottom of the current deck
 /// </summary>
 /// <param name="AppendDeck">Deck of cards to append</param>
 public void Append(Deck AppendDeck)
 {
     if (this.NumCards == 0)
     {
         this.FirstCard = AppendDeck.FirstCard;
         this.LastCard = AppendDeck.LastCard;
     }
     this.LastCard.NextCard = AppendDeck.FirstCard;
     this.LastCard = AppendDeck.LastCard;
     this.NumCards += AppendDeck.NumCards;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Add a card to the end of the deck
        /// </summary>
        /// <param name="cToAdd">Card to Add</param>
        /// <param name="bCheckAllow">First verify allowed</param>
        /// <returns></returns>
        public bool Add(Card cToAdd, bool bCheckAllow)
        {
            if (bCheckAllow && !this.CanAdd(cToAdd)) return false;

            if (this.NumCards == 0)
                this.FirstCard = cToAdd;
            else if (this.LastCard != null)
                this.LastCard.NextCard = cToAdd;
            cToAdd.NextCard = null;
            this.LastCard = cToAdd;
            this.NumCards++;
            return true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates all 13 cards of the same suit
        /// </summary>
        /// <param name="suit"></param>
        /// <returns></returns>
        protected Deck SingleSuit(CardSuit suit)
        {
            Deck ToReturn = new Deck();
            Card ToAdd;

            for(int i = 0; i < 13; i++)
            {
                ToAdd = new Card(suit, (CardValue)i);
                ToReturn.Add(ToAdd);
                if (i == 0) ToReturn.FirstCard = ToAdd;
                if (i == 13) ToReturn.LastCard = ToAdd;
            }

            return ToReturn;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Remove a card from a deck and return that card
        /// </summary>
        /// <param name="iIndex">0-based index of the card to remove</param>
        /// <returns></returns>
        public Card Remove(int iIndex)
        {
            Card current = this.FirstCard;
            Card remove;
            int iAdjIndex = iIndex - 1;

            if (iIndex < 0 || iIndex >= this.NumCards)
            {
                throw new IndexOutOfRangeException("Trying to remove non-existant card: " + iIndex);
            }
            else if (iIndex == 0)
            {
                remove = this.FirstCard;
                this.FirstCard = remove.NextCard;
                remove.NextCard = null;
            }
            else
            {
                for (int i = 0; i < iAdjIndex; i++)
                    current = current.NextCard;
                // x is now the card before the card to remove (index)
                remove = current.NextCard;
                if (this.LastCard == remove)
                    this.LastCard = current;
                current.NextCard = remove.NextCard;
                remove.NextCard = null;
            }

            this.NumCards--;
            return remove;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Determine if a deck contains a given card
        /// </summary>
        /// <param name="suit">Suit of card to find</param>
        /// <param name="val">Value of card to find</param>
        /// <returns></returns>
        public bool Contains(CardSuit suit, CardValue val)
        {
            Card findme = new Card(suit, val);
            Card current = this.FirstCard;

            Console.WriteLine("Contains check");

            while (current != null)
            {
                if (current.Equals(findme)) return true;
                current = current.NextCard;
            }

            return false;
        }
Exemplo n.º 6
0
 /// <summary>
 /// If Allowed, add a card to the end of the deck
 /// </summary>
 /// <param name="card">Card to add</param>
 public bool Add(Card cToAdd)
 {
     return this.Add(cToAdd, true);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Determine if a given card can be added to this deck
 /// </summary>
 /// <param name="cToAdd"></param>
 /// <returns></returns>
 public virtual bool CanAdd(Card cToAdd)
 { return true; }
Exemplo n.º 8
0
 public Deck()
 {
     this.FirstCard = null;
     this.LastCard = null;
     this.NumCards = 0;
 }
Exemplo n.º 9
0
 public Card(CardSuit suit, CardValue value, Card nextcard)
 {
     this.Suit = suit;
     this.Value = value;
     this.NextCard = nextcard;
 }
Exemplo n.º 10
0
 public Card(CardSuit suit, CardValue value)
 {
     this.Suit = suit;
     this.Value = value;
     this.NextCard = null;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Displays the current state of the 8 columns
        /// </summary>
        /// <param name="gi"></param>
        static private void DisplayColumns(GameInfo gi)
        {
            Card[] CurrCard = new Card[NUM_COLS];
            bool bDisplayedAll = false;

            // seed to first cards
            for (int i = 0; i < NUM_COLS; i++)
            { CurrCard[i] = gi.Columns[i].FirstCard; }

            for (int i = 0; i < NUM_COLS; i++)
            {   Console.Write(" " + (i + 1).ToString("D2") + " ");  }
            Console.Write("\n");

            for (int i = 0; i < NUM_COLS; i++)
            {   Console.Write(" -- ");  }
            Console.Write("\n");

            while(!bDisplayedAll)
            {
                for (int i = 0; i < NUM_COLS; i++)
                {
                    if (CurrCard[i] != null)
                    {
                        //Console.Write(" " + CurrCard[i].ToString() + " ");
                        CurrCard[i].OutputCardAbbrev(" ", " ");
                        CurrCard[i] = CurrCard[i].NextCard;
                    }
                    else
                        Console.Write("    ");
                }
                Console.Write("\n");

                bDisplayedAll = true;
                for(int i = 0; i < NUM_COLS; i++)
                {
                    if (CurrCard[i] != null)
                        bDisplayedAll = false;
                }
            }
        }