Пример #1
0
 private void BlackJackTable_Load(object sender, EventArgs e)
 {
     // Shuffle a new deck when the form loads and update
     // the player stats in the corner.
     currentDeck = new ActiveDeck(SourceDeck, false);
     UpdatePlayerStats();
 }
Пример #2
0
        public int GetHandValue()
        {
            // Function to return value of player's hand
            // anytime it's needed.

            int returnValue  = 0;
            int numberOfAces = 0;

            try
            {
                // For each card in the hand, call the static function
                // GetCardValue in the ActiveDeck class and return sum.
                foreach (PlayingCard c in cPlayerhand)
                {
                    // Only count face up cards.
                    if (!c.FaceDown)
                    {
                        // Count Aces last.
                        if (c.CardName.ToUpper().StartsWith("ACE"))
                        {
                            numberOfAces++;
                        }
                        else
                        {
                            returnValue += ActiveDeck.GetCardValue(c.CardName);
                        }
                    }
                }

                // For each Ace, add 11 if the hand is 10 or less.
                // Otherwise, add 1.
                for (int x = 1; x <= numberOfAces; x++)
                {
                    if (returnValue > 10)
                    {
                        returnValue++;
                    }
                    else
                    {
                        returnValue += 11;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(returnValue);
        }