예제 #1
0
        /// <summary>
        /// Utility method to deal a card, also handles aces and first run of cards
        /// </summary>
        /// <param name="who">Which player</param>
        /// <param name="firstRun">Prevent message box and assign default value of 1 for aces</param>
        /// <returns></returns>
        private Card DealCardTo(int who, bool firstRun)
        {
            Card card = TwentyOneGame.DealOneCardTo(who);

            // Is it an ace
            if (!firstRun && who == TwentyOneGame.PLAYER_USER && card.GetFaceValue() == FaceValue.Ace)
            {
                if (MessageBox.Show("Count ace as 1?", this.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    TwentyOneGame.IncrementNumOfUserAcesWithValueOne();
                }
            }

            this.UpdateDisplay(false);

            return(card);
        }
예제 #2
0
        /// <summary>
        /// Play the game on click of the hit button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void hitButton_Click(object sender, EventArgs e)
        {
            Card playerDeltCard = TwentyOneGame.DealOneCardTo(PLAYER);

            FaceValue faceValueOfDeltCard = playerDeltCard.GetFaceValue();

            if (faceValueOfDeltCard == FaceValue.Ace)
            {
                DialogResult messageBoxResult = ClassAssignment.Program.showYesNoMessageBox("Count Ace as 1?", "You got an Ace!");
                if (messageBoxResult == DialogResult.Yes)
                {
                    TwentyOneGame.IncrementNumOfUserAcesWithValueOne();
                }
            }

            checkPlayerBusted(PLAYER);
            UpdateDynamicValues(PLAYER);
            checkExceedMaximumCards(PLAYER);
        }
예제 #3
0
        }     //end of DealButton_Click

        private void HitButton_Click(object sender, EventArgs e)
        {
            //Ask player if they want to use Ace as 1.
            if (TwentyOneGame.DealOneCardTo(1).GetFaceValue() == FaceValue.Ace)
            {
                DialogResult choice = MessageBox.Show("Count Ace as 1?", "You got an Ace!",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                //If choice is Yes, Ace card is given a 1 value.
                if (choice == DialogResult.Yes)
                {
                    TwentyOneGame.IncrementNumOfUserAcesWithValueOne();
                    AmountOfAcesAsOne.Text = TwentyOneGame.GetNumOfUserAcesWithValueOne().ToString();
                } //end of if statement
            }     //end of if statement

            //Calculates totals.
            TwentyOneGame.CalculateHandTotal(1);

            //Updates the points text.
            PointsLabel2.Text = TwentyOneGame.GetTotalPoints(1).ToString();

            //Updates GUI panels.
            DisplayGuiHand(TwentyOneGame.GetHand(1), LayoutPanel2);

            //If players points go over 21..
            if (TwentyOneGame.GetTotalPoints(1) > 21)
            {
                //Show BUSTED label.
                BustedLabel2.Visible = true;

                //Updates games won.
                Number1.Text = TwentyOneGame.GetNumOfGamesWon(0).ToString();

                //Enables DealButton again for another Game, and disables Hit and stand buttons.
                DealButton.Enabled  = true;
                HitButton.Enabled   = false;
                StandButton.Enabled = false;
            } //end of if statement
        }     //end of HitButton_Click