Ejemplo n.º 1
0
        private void PlayOneRoundOfBlackJack(BlackJackGame game, int bet)
        {
            game.StartNewGame(bet);

            while (game.GameRunning)
            {
                Console.WriteLine("Dealer: {0}", game.GetVisibleDealerCardsAsString());
                Console.WriteLine("Player: {0}", game.GetPlayerCardsAsString());

                Console.WriteLine("One more card (Y/N)?");

                char entry = ' ';
                while ('Y' != entry && 'N' != entry)
                {
                    entry = Char.ToUpper(Console.ReadKey().KeyChar);
                }

                if ('Y' == entry)
                {
                    game.Hit();
                }
                else
                {
                    game.Stand();
                }
            }

            DisplayBlackJackResult(game);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Event Handler that runs when the user clicks on the hit button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnHitClick(object sender, RoutedEventArgs e)
        {
            //if the player is able to hit
            if (_game.Hit() == true)
            {
                //don't let them double - following blackjack rules
                _btnDouble.IsEnabled = false;

                //redraw the player's hand (now with an additonal card than before)
                DrawCardsBE(_canvasPlayerHand, _game.Player.Hand, Alignment.Center);

                //if the player has a soft-hand value
                if (_game.Player.SoftHandValue != 0)
                {
                    //update the label to show the player's score and soft-hand score
                    _txtPlayerTotal.Text = $"{_game.Player.Score.ToString()}/{_game.Player.SoftHandValue.ToString()}";
                }

                //if the player does not have a soft-hand value
                else
                {
                    //don't show the soft-hand score, only show the score
                    _txtPlayerTotal.Text = _game.Player.Score.ToString();
                }

                //if the score of the player is 21
                if (_game.Player.Score == 21)
                {
                    //disable the buttons
                    _btnHold.IsEnabled = false;
                    _btnHit.IsEnabled  = false;

                    //start the dealer card timer to add dealer cards - this is done automatically as the user has hit 21 (the best score possible)
                    _tmDealerCardTimer.Start();
                }

                //if the player score is greater than 21
                if (_game.Player.Score > 21)
                {
                    //end the round, pasisng the method the appropriate message
                    EndRound("PLAYER BUST, DEALER WINS");
                }
            }
        }