Example #1
0
 /// <summary>
 /// Converts a card to text to be displayed in the console.
 /// </summary>
 /// <param name="card">The card.</param>
 /// <returns></returns>
 static string CardToText(Card card)
 {
     string output = "";
     switch (card.Suit)
     {
         case CardSuit.Club:     output += "♣"; break;
         case CardSuit.Diamond:  output += "♦"; break;
         case CardSuit.Heart:    output += "♥"; break;
         case CardSuit.Spade:    output += "♠"; break;
     }
     switch (card.Rank)
     {
         case CardRank.Ace:     output += "A "; break;
         case CardRank.Two: output += "2 "; break;
         case CardRank.Three: output += "3 "; break;
         case CardRank.Four: output += "4 "; break;
         case CardRank.Five: output += "5 "; break;
         case CardRank.Six: output += "6 "; break;
         case CardRank.Seven: output += "7 "; break;
         case CardRank.Eight: output += "8 "; break;
         case CardRank.Nine: output += "9 "; break;
         case CardRank.Ten: output += "T"; break;
         case CardRank.Jack: output += "J "; break;
         case CardRank.Queen: output += "Q "; break;
         case CardRank.King: output += "K "; break;
     }
     return output;
 }
Example #2
0
        /// <summary>
        /// Checks to see if it is possible to move the specified <see cref="Card"/> to the specified <see cref="Cascade"/>.
        /// </summary>
        /// <param name="card">The <see cref="Card"/> to check if its possible to move to the specified <see cref="Cascade"/></param>
        /// <param name="cascade">The <see cref="Cascade"/> that will be holding the specified <see cref="Card"/></param>
        /// <returns><c>true</c> if the specified <see cref="Card"/> can be moved to the specified <see cref="Stack"/>; otherwise <c>false</c></returns>
        public virtual bool CanMoveToCascade(Card card, Cascade cascade)
        {
            if (!EnforceRules)
                return true;

            if (cascade.Count == 0)
                return true;
            if (DoCardsLinkInCascade(card, cascade.Last()))
                return true;
            return false;
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameCard"/> class.
 /// </summary>
 public GameCard(Card card)
 {
     InitializeComponent();
     _card = card;
     Initialize();
 }
Example #4
0
        /// <summary>
        /// Gets a value indicating if the top card can sit on top of the bottom card in the foundation.
        /// </summary>
        /// <param name="topCard">The top card (moving card)</param>
        /// <param name="bottomCard">The bottom card (destination card).</param>
        /// <returns><c>true</c> if these two cards can link in the foundation; otherwise <c>false</c>.</returns>
        public virtual bool DoCardsLinkInFoundation(Card topCard, Card bottomCard)
        {
            if (!EnforceRules)
                return true;

            if ((topCard.Suit == bottomCard.Suit) && ((topCard.Rank - 1) == bottomCard.Rank))
                return true;
            return false;
        }
Example #5
0
        /// <summary>
        /// Gets a value indicating if the top card can sit on top of the bottom card while moving to a cascade.
        /// </summary>
        /// <param name="topCard">The top card (moving card)</param>
        /// <param name="bottomCard">The bottom card (destination card).</param>
        /// <returns><c>true</c> if these two cards can link in the cascade; otherwise <c>false</c>.</returns>
        public virtual bool DoCardsLinkInCascade(Card topCard, Card bottomCard)
        {
            if (!EnforceRules)
                return true;

            if (bottomCard == null)
                return true;

            if ((topCard.Color != bottomCard.Color) && ((topCard.Rank + 1) == bottomCard.Rank))
                return true;
            return false;
        }
Example #6
0
 /// <summary>
 /// Checks to see if it is possible to move the specified <see cref="Card"/> to the specified <see cref="Foundation"/>.
 /// </summary>
 /// <param name="card">The <see cref="Card"/> to check if its possible to move to the specified <see cref="Foundation"/></param>
 /// <param name="foundation">The <see cref="Foundation"/> to check if its possible to move to the specified <see cref="Card"/> to</param>
 /// <returns><c>true</c> if the specified <see cref="Card"/> can be moved to the specified <see cref="Foundation"/>; otherwise <c>false</c></returns>
 public virtual bool CanMoveToFoundation(Card card, Foundation foundation)
 {
     if (!EnforceRules)
         return true;
     if (foundation.Count == 0)
     {
         if (card.Rank == CardRank.Ace)
             return true;
     }
     else
     {
         if ((foundation.Last<Card>().Suit == card.Suit) && ((foundation.Last<Card>().Rank + 1) == card.Rank))
             return true;
     }
     return false;
 }
Example #7
0
        /// <summary>
        /// Checks to see if it is possible to move the specified <see cref="Card"/> to the specified <see cref="Cell"/>.
        /// </summary>
        /// <param name="card">The <see cref="Card"/> to check if its possible to move to the specified <see cref="Cell"/></param>
        /// <param name="cell">The destination <see cref="Cell"/> to hold the specified <see cref="Card"/></param>
        /// <returns><c>true</c> if the specified <see cref="Card"/> can be moved to the specified <see cref="Cell"/>; otherwise <c>false</c></returns>
        public virtual bool CanMoveToCell(Card card, Cell cell)
        {
            if (!EnforceRules)
                return true;

            if (!cell.HasCard)
                return true;
            return false;
        }
Example #8
0
        /// <summary>
        /// Draws the card.
        /// </summary>
        /// <param name="top">The top.</param>
        /// <param name="left">The left.</param>
        /// <param name="card">The card.</param>
        static void DrawCard(int top, int left, Card card)
        {
            Console.SetCursorPosition(left, top);
            Console.Write("┌");
            for (int i = 0; i < CardWidth; i++)
                Console.Write("─");
            Console.Write("┐");

            Console.SetCursorPosition(left, ++top);
            Console.Write("│");
            if(card != null)
            {
                string text = CardToText(card);
                Console.Write(text.PadRight(CardWidth));
            }
            else
            {
                for(int i = 0; i < CardWidth; i++)
                    Console.Write(" ");
            }
            Console.Write("│");
            for (int i = 0; i < (CardHeight-1); i++)
            {
                Console.SetCursorPosition(left, ++top);
                Console.Write("│");
                for (int j = 0; j < CardWidth; j++)
                    Console.Write(" ");
                Console.Write("│");
            }
            Console.SetCursorPosition(left, ++top);
            Console.Write("└");
            for (int i = 0; i < CardWidth; i++)
                Console.Write("─");
            Console.Write("┘");
        }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AutoBankEventArgs"/> class.
 /// </summary>
 public AutoBankEventArgs(Card card)
 {
     Card = card;
 }