コード例 #1
0
        // this should only happen if the player hits 21 or hits stand
        public void DealerTurn()
        {
            btnHit.IsEnabled   = false;
            btnStand.IsEnabled = false;

            if (dealerHand.handWorth < playerHand.handWorth)
            {
                while (dealerHand.handWorth < 17 || (dealerHand.handWorth < playerHand.handWorth && playerHand.handWorth <= 21))
                {
                    Card newCard = currentDeck.dealCard();
                    dealerHand.addCardToHand(newCard);
                    lblDealerCards.Content += newCard.cardWorth.ToString() + " ";
                }
            }

            if (Bust(dealerHand))
            {
                if (Bust(playerHand))
                {
                    // dealer still wins
                    dealerWins(1);
                    return;
                }
                else
                {
                    // dealer loses
                    playerWins(1);
                    return;
                }
            }
            else if (playerHand.handWorth == dealerHand.handWorth)
            {
                // player loses and dealer gets a point
                dealerWins(1);
                return;
            }
            else if (dealerHand.handWorth == 21)
            {
                dealerWins(2);
                return;
            }
            else if (dealerHand.handWorth > playerHand.handWorth)
            {
                dealerWins(1);
                return;
            }
            // This shouldn't be hit, but leaving here in case logic changes in future
            else if (dealerHand.handWorth == 21 && playerHand.handWorth == 21)
            {
                bothWin(1);
                return;
            }
        }
コード例 #2
0
        private void btnHit_Click(object sender, RoutedEventArgs e)
        {
            int  currentWorth = playerHand.handWorth;
            Card newCard      = currentDeck.dealCard();

            playerHand.addCardToHand(newCard);
            currentWorth += newCard.cardWorth;
            lblPlayerHandWorth.Content = currentWorth.ToString();
            lblPlayerCards.Content    += newCard.cardWorth.ToString() + " ";
            if (Bust(playerHand))
            {
                // player loses
                dealerWins(1);
                return;
            }
        }