Exemple #1
0
            /// <summary>
            /// Returns card in deck that matches an ambiguous card where suit is missing.
            /// </summary>
            /// <exception cref="CardNotPresentException">No cards that match this value.</exception>
            /// <exception cref="AmbiguousCardException">Several cards match this value.</exception>
            private static byte GetCardByValue(byte cardWithNoSuit, List <byte> deckToCheckAgainst)
            {
                byte     card        = 0;
                CardVals ambiCardVal = Defs.GetCardValue(cardWithNoSuit);

                foreach (byte deckCard in deckToCheckAgainst)
                {
                    if (Defs.GetCardValue(deckCard) == ambiCardVal)
                    {
                        if (card == 0)
                        {
                            card = deckCard;
                        }
                        else
                        {
                            throw new AmbiguousCardException("Card suit must be specified, as the card referral is ambiguous.", cardWithNoSuit);
                        }
                    }
                }
                if (card == 0)
                {
                    throw new CardNotPresentException("Card was specified by value, but no such value exists in this grouping of cards.", cardWithNoSuit);
                }
                return(card);
            }
Exemple #2
0
        /// <summary>
        /// Writes all remaining cards in Deck to the Command Prompt, and returns what was printed as a string.
        /// </summary>
        public string PrintDeck(bool newLine = false, bool shorthand = false, bool ascii = false)
        {
            //TODO: replace this with Defs.PrintCards
            StringBuilder result    = new StringBuilder();
            List <byte>   localDeck = _cardDeck;
            string        sep       = newLine ? "\n" : ", ";

            for (int i = 0; i < CardCount; i++)
            {
                string statement = (!shorthand) ? Defs.PrintCard(localDeck[i]) + sep
                    : Defs.PrintCardShorthand(localDeck[i], ascii) + sep;
                result.Append(statement);
            }
            Console.WriteLine(result.ToString());
            return(result.ToString());
        }