Пример #1
0
        /// <summary>
        /// When the player stands, the dealer then hits
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnStand_Click(object sender, RoutedEventArgs e)
        {
            while (game.dealerHand.getHandValue() < 17 || game.dealerHand.getHandValue() < game.player1Hand.getHandValue())
            {
                await Task.Delay(2000);

                game.DealerHit();

                PopulateBoard();
            }

            // Show dealer's first card
            dealerCards[0].Source = new BitmapImage(new Uri("cards/" + game.dealerHand.hand[0].rank + "_of_" + game.dealerHand.hand[0].suit + ".jpg", UriKind.Relative));

            // If dealer busts
            if (game.dealerHand.getHandValue() > 21)
            {
                results            = new wndResults("Dealer Busts!");
                game.player1Score += 1;
                results.ShowDialog();

                // Reset game
                game.ClearBoard();
                PopulateBoard();
            }
            // If dealer has higher total
            else if (game.dealerHand.getHandValue() > game.player1Hand.getHandValue())
            {
                results           = new wndResults("Dealer Wins!");
                game.dealerScore += 1;
                results.ShowDialog();

                // Reset game
                game.ClearBoard();
                PopulateBoard();
            }
            // If player has higher total
            else if (game.player1Hand.getHandValue() > game.dealerHand.getHandValue())
            {
                results            = new wndResults("You Win!");
                game.player1Score += 1;
                results.ShowDialog();

                // Reset game
                game.ClearBoard();
                PopulateBoard();
                btnHit.Visibility = Visibility.Visible;
            }
        }
Пример #2
0
        private void btnHit_Click(object sender, RoutedEventArgs e)
        {
            game.playerHit();

            PopulateBoard();

            if (game.player1Hand.getHandValue() > 21)
            {
                results           = new wndResults("Bust!");
                game.dealerScore += 1;
                results.ShowDialog();

                //Reset game
                game.ClearBoard();
                PopulateBoard();
            }
            else if (game.player1Hand.getHandValue() == 21)
            {
                btnHit.Visibility = Visibility.Hidden;
            }
        }