Exemple #1
0
        public string ToString(string format)
        {
            if (format == null)
            {
                format = "G";
            }

            string suitSeperator;
            bool   showSuit;

            switch (format)
            {
            case "G":
                suitSeperator = "; ";
                showSuit      = true;
                break;

            case "N":
                suitSeperator = Environment.NewLine;
                showSuit      = true;
                break;

            case "P":
                if (Cards.Count == 0)
                {
                    return("-");
                }
                suitSeperator = ".";
                showSuit      = false;
                break;

            default:
                throw new FormatException("Unknown format specifier.");
            }
            ;

            StringBuilder s        = new StringBuilder();
            var           lastSuit = Card.SuitsDescending[Card.SuitCount - 1];
            var           cards    = new CardCollection();

            cards.AddRange(this.Cards);
            cards.Sort((a, b) => (int)b.Rank - (int)a.Rank);
            foreach (var suit in Card.SuitsDescending)
            {
                if (showSuit)
                {
                    s.Append(Card.SuitGlyph[(int)suit]);
                    s.Append(' ');
                }

                foreach (Card card in cards)
                {
                    if (card.Suit == suit)
                    {
                        s.Append(card.ToString("P")[1]);
                    }
                }

                if (suit != lastSuit && (!showSuit || s.Length > 0))
                {
                    if (s.Length > 0 && s[s.Length - 1] == ' ')
                    {
                        s.Length -= 1;
                    }
                    s.Append(suitSeperator);
                }
            }

            return(s.ToString().Trim());
        }
Exemple #2
0
 public Hand()
 {
     Cards = new CardCollection();
 }