예제 #1
0
        /// <summary>
        /// Sorts the card by their suit
        /// </summary>
        /// <param name="pile"></param>
        /// <returns></returns>
        public static Pile SortBySuit(Pile pile)
        {
            System.Collections.ArrayList newHand = new System.Collections.ArrayList();

            System.Collections.ArrayList CardPile = (System.Collections.ArrayList)pile.CardPile;


            while (CardPile.Count > 0)
            {
                int        pos           = 0;                       // Position of minimal card.
                SpadesCard minSpadescard = (SpadesCard)CardPile[0]; // Minimal card.
                int        mincard       = (int)minSpadescard.CardIndex;
                for (int i = 1; i < CardPile.Count; i++)
                {
                    SpadesCard nextSpadescard = (SpadesCard)CardPile[i];
                    int        nextcard       = nextSpadescard.CardIndex;
                    if (Card.SuitFromCardIndex(nextcard) < Card.SuitFromCardIndex(mincard)
                        ||
                        (Card.SuitFromCardIndex(nextcard) == Card.SuitFromCardIndex(mincard) && Card.RankFromCardIndex(nextcard) < Card.RankFromCardIndex(mincard))
                        )
                    {
                        pos           = i;
                        mincard       = nextcard;
                        minSpadescard = nextSpadescard;
                    }
                }
                CardPile.RemoveAt(pos);
                newHand.Add(minSpadescard);
            }
            CardPile      = newHand;
            pile.CardPile = CardPile;

            return(pile);
        }
예제 #2
0
 /// <summary>
 /// constructor of spades card
 /// </summary>
 /// <param name="i">Card Index</param>
 public SpadesCard(int i)
     : base()
 {
     if (i < 0 || i > 52)
     {
         throw new ApplicationException("Wrong value for card initilization.");
     }
     _cardindex = i;
     Suit       = Card.SuitFromCardIndex(i);
     Rank       = Card.RankFromCardIndex(i);
 }
예제 #3
0
 /// <summary>
 /// checks the hand if it has the passed suit or not
 /// </summary>
 /// <param name="suit">Suit of the card to check.</param>
 /// <param name="hand">Hand of the player to check in.</param>
 /// <returns></returns>
 public static bool hasSuit(CardSuit suit, Hand hand)
 {
     foreach (SpadesCard card in hand.CardPile)
     {
         if (Card.SuitFromCardIndex(card.CardIndex) == suit)
         {
             return(true);
         }
     }
     return(false);
 }