コード例 #1
0
        /// <summary>
        /// Method used to perform actions when the round ends
        /// </summary>
        /// <param name="endReason">taakes a string value for the reason as to why the round has ended</param>
        private async void EndRound(string endReason)
        {
            //stop the dealer card timer
            _tmDealerCardTimer.Stop();

            //disable the game buttons
            _btnHold.IsEnabled   = false;
            _btnHit.IsEnabled    = false;
            _btnDouble.IsEnabled = false;

            _uiFinalTextBorder.Visibility = Visibility.Visible;

            //set the displayed message to be the string passed as a parameter
            _txtDisplayOutcome.Text = endReason;

            //delay the program
            await Task.Delay(TimeSpan.FromMilliseconds(3000));

            _started = false;

            //clear the canvases
            _canvasDealerHand.Children.Clear();
            _canvasPlayerHand.Children.Clear();

            _btnOpenPane.IsEnabled  = true;
            _btnOpenPane.Visibility = Visibility.Visible;

            //update controls
            _txtGameMoney.Text = (_game.Payout().ToString());
            _txtChipCount.Text = $"CHIP TOTAL: {_game.Player.GameMoney.ToString()}";

            //if the player has chips remaining
            if (_game.Player.GameMoney != 0)
            {
                //draw the player chip stack and allow them to click on them to bet
                _uiPlayerChips.Stroke   = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                _uiPlayerChips.Fill     = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
                _uiPlayerChip.IsEnabled = true;

                //ask the user to bet chips to start the round
                _txtDisplayOutcome.Text = "CLICK ON A CHIP TO MAKE A BET";
            }
            //if the player does not have chips remaining
            else
            {
                //ask them to go to the menu to buy chips
                _txtDisplayOutcome.Text = "CLICK 'USER MENU' TO BUY CHIPS";

                _txtGameMoney.Text = "";
            }

            //save the game at the end of each round
            SaveGame();

            //make the bet area look empty
            _uiBetArea.Stroke = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
            _uiBetArea.Fill   = new SolidColorBrush();

            //reset controls and variables
            _uiDealerScoreBorder.Visibility = Visibility.Collapsed;

            _game.Player.Bet = 0;
            _txtBet.Text     = "";

            _txtPlayerTotal.Text = "";
        }