Ejemplo n.º 1
0
        /// <summary>
        /// Event Handler that runs on each tick of the dealer timer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDealerCardTimerTick(object sender, object e)
        {
            //if this is the first time the timer has ticked
            if (_firstTimerTick == true)
            {
                //turn the cards face up and re-draw them
                _game.Dealer.TurnCardsFaceUp();
                DrawCardsBE(_canvasDealerHand, _game.Dealer.Hand, Alignment.Center);

                //show the dealer's score
                _uiDealerScoreBorder.Visibility = Visibility.Visible;

                //if the dealer has a soft-hand value
                if (_game.Dealer.SoftHandValue != 0)
                {
                    //show the score and soft-hand value
                    _txtDealerTotal.Text = $"{_game.Dealer.Score.ToString()}/{_game.Dealer.SoftHandValue.ToString()}";
                }

                //if the dealer does not have a soft-hand value
                else
                {
                    //show the score of the player
                    _txtDealerTotal.Text = _game.Dealer.Score.ToString();
                }

                //ensure the above code only runs the first tick by setting the boolean to false
                _firstTimerTick = false;
            }

            //if this is not the first time the timer has ticked
            else
            {
                //if the dealer's soft-hand value is 17 or above
                if (_game.Dealer.SoftHandValue >= 17)
                {
                    //set the dealer score to the soft-hand value and update the label
                    _game.Dealer.Score   = _game.Dealer.SoftHandValue;
                    _txtDealerTotal.Text = _game.Dealer.Score.ToString();
                }

                //if the dealer's score is between 17 and 21
                if (_game.Dealer.Score >= 17 && _game.Dealer.Score <= 21)
                {
                    //end the round - blackjack rules - dealer cannot hit after it reaches a score (or soft-hand score) of 17 or above
                    EndRound(_game.DetermineWinner());
                }

                //if the dealer's score is less than 17
                else
                {
                    if (_game.Hold() == true)
                    {
                        //if the dealer has a soft-hand value
                        if (_game.Dealer.SoftHandValue != 0)
                        {
                            //show the score and soft-hand core of the dealer
                            _txtDealerTotal.Text = $"{_game.Dealer.Score.ToString()}/{_game.Dealer.SoftHandValue.ToString()}";
                        }

                        //if the dealer does not have a soft-hand score
                        else
                        {
                            //show the score
                            _txtDealerTotal.Text = _game.Dealer.Score.ToString();
                        }

                        //draw the cards again
                        DrawCardsBE(_canvasDealerHand, _game.Dealer.Hand, Alignment.Center);

                        //if the dealer score is greater than 21
                        if (_game.Dealer.Score > 21)
                        {
                            //end the round - dealer busted
                            EndRound("DEALER BUST, PLAYER WINS");
                        }
                    }

                    //if the dealer has reached a score of above 17
                    else
                    {
                        //stop the card timer
                        _tmDealerCardTimer.Stop();

                        //if their score is less than or equal to 17
                        if (_game.Dealer.Score <= 21)
                        {
                            //end the round
                            EndRound(_game.DetermineWinner());
                        }
                    }
                }
            }
        }