コード例 #1
0
        private void Deal_button_Click(object sender, EventArgs e)
        {
            Twenty_One_Game.SetUpGame();
            DisplayGuiHand(Twenty_One_Game.GetHand(0), dealerTableLayoutPanel);
            DisplayGuiHand(Twenty_One_Game.GetHand(1), playerTableLayoutPanel);
            this.Deal_button.Enabled         = false;
            this.Hit_button.Enabled          = true;
            this.Stand_button.Enabled        = true;
            this.BUSTED_DEALER_label.Visible = false;
            this.BUSTED_PLAYER_label.Visible = false;

            for (card_index = 0; card_index < Twenty_One_Game.GetHand(1).GetCount(); card_index++)
            {
                if (Twenty_One_Game.GetHand(1).GetCard(card_index).GetFaceValue().ToString() == "Ace")
                {
                    DialogResult result = MessageBox.Show("Count Ace as one?", "You Got An Ace", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    // If the user clicked the Yes button
                    if (result == DialogResult.Yes)
                    {
                        Twenty_One_Game.IncrementNumOfUserAcesWithValueOne(1);
                        number_of_ace++;
                        this.label1.Text = number_of_ace.ToString();
                    }
                }
            }

            int dealer_points = Twenty_One_Game.CalculateHandTotal(0);
            int player_points = Twenty_One_Game.CalculateHandTotal(1);

            show_points(dealer_points, player_points);
            check_if_player_points_exceeds_limit(player_points);
        }
コード例 #2
0
        private void btnDeal_Click(object sender, EventArgs e)
        {
            Twenty_One_Game.SetUpGame();

            // Hide busted message(s)
            HideBustedMessage();

            // Reset Ace counter label
            DisplayAcesValueOne();

            // Diplay dealt cards for player and dealer
            DisplayGuiHand(Twenty_One_Game.GetHand(PLAYER), tblPanelPlayer);
            DisplayGuiHand(Twenty_One_Game.GetHand(DEALER), tblPanelDealer);

            // Calcualte hand totals for player and dealer on first draw
            Twenty_One_Game.CalculateHandTotal(PLAYER);
            Twenty_One_Game.CalculateHandTotal(DEALER);

            // Display points for player and dealer
            DisplayPoints();

            // Check if initial player hand includes an Ace
            CheckPlayerHandForAce();

            DisableDealButton();

            // Enable buttons for next stage of game
            EnableHitButton();
            EnableStandButton();

            // Check for dual ace automatic dealer bust
            AutomaticDealerBust();
        } // end btnDeal_Click
コード例 #3
0
ファイル: Twenty_one.cs プロジェクト: I3un/CAB201
 private void standButton_Click(object sender, EventArgs e) {
     //Twenty_One_Game.ResetTotals();
     hitButton.Enabled = false;
     standButton.Enabled = false;
     dealButton.Enabled = true;
     while (Twenty_One_Game.GetTotalPoints(FIRST_PLAYER) > Twenty_One_Game.GetTotalPoints(COMPUTER)) {
         Twenty_One_Game.PlayForDeal();
         DisplayGuiHand(Twenty_One_Game.GetHand(COMPUTER), topTableLayoutPanel);
         Twenty_One_Game.CalculateHandTotal(COMPUTER);
     }
     pointDealerLabel.Text = Twenty_One_Game.GetTotalPoints(COMPUTER).ToString();
     if (Twenty_One_Game.GetTotalPoints(COMPUTER) > 21
         || Twenty_One_Game.GetTotalPoints(COMPUTER) < Twenty_One_Game.GetTotalPoints(FIRST_PLAYER)) {
         dealerBustedLabel.Visible = true;
         numberPlayerLabel.Text = Twenty_One_Game.GetNumOfGamesWon(FIRST_PLAYER).ToString();
         hitButton.Enabled = false;
         standButton.Enabled = false;
         dealButton.Enabled = true;
     }
     else if (Twenty_One_Game.GetTotalPoints(FIRST_PLAYER) > 21
         || Twenty_One_Game.GetTotalPoints(FIRST_PLAYER) < Twenty_One_Game.GetTotalPoints(COMPUTER)) {
         playerbustedLabel.Visible = true;
         numberDealerLabel.Text = Twenty_One_Game.GetNumOfGamesWon(COMPUTER).ToString();
         hitButton.Enabled = false;
         standButton.Enabled = false;
         dealButton.Enabled = true;
     }
 }
コード例 #4
0
        /// <summary>
        /// Plays again for dealer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            Hand HandForDealer = Twenty_One_Game.GetHand(Twenty_One_Game.DEALER);

            Twenty_One_Game.PlayForDealer();
            hpoints.Text = String.Format("{0}", Twenty_One_Game.CalculateHandTotal(Twenty_One_Game.DEALER));
            DisplayGuiHand(HandForDealer, tableLayoutPanel1);
            //Buested();
        }
コード例 #5
0
        }//end cancelButton

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dealButton_Click(object sender, EventArgs e)
        {
            int dealerTotal;
            int userTotal;
            int decrementScoreBy = 10;

            //resets ace label value
            aceLabel.Text = "0";
            Twenty_One_Game.SetNumOfAcesValuedOneToZero();
            //ensures the bust labels are not visible at the start of a second game
            dBust.Visible = false;
            pBust.Visible = false;
            Twenty_One_Game.DealOneCardTo(0); //deals one card to dealer
            Twenty_One_Game.DealOneCardTo(0); //deals second card to dealer
            Twenty_One_Game.DealOneCardTo(1); //deals one card to user
            Twenty_One_Game.DealOneCardTo(1); //deals second card to user
            //displays images of dealer and users hands
            DisplayGuiHand(Twenty_One_Game.GetHand(0), dealerTableLayoutPanel);
            DisplayGuiHand(Twenty_One_Game.GetHand(1), userTableLayoutPanel);
            //resets the GUI buttons for next play
            dealButton.Enabled  = false;
            hitButton.Enabled   = true;
            standButton.Enabled = true;
            //Calculates hand total for dealer then the user
            dealerTotal = Twenty_One_Game.CalculateHandTotal(0);
            userTotal   = Twenty_One_Game.CalculateHandTotal(1);

            foreach (Card card in Twenty_One_Game.GetHand(1))
            {
                if (card.GetFaceValue() == FaceValue.Ace)
                {
                    //displays message box asking user whether to count ace as 1
                    DialogResult dialogResult = MessageBox.Show("Count Ace as 1?", "You got an Ace!", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        //increments numofuseraceswithvalueone if user clicks yes
                        Twenty_One_Game.IncrementNumofUserAcesWithValueOne();
                        //updates aceLabel with the number of aces
                        aceLabel.Text = Twenty_One_Game.GetNumOfUserAcesWithValueOne().ToString();
                    } //end nested if
                }     //end if
            }         //end foreach


            //decrements user total by the number of aces multipled by the decrement value of 10
            userTotal = userTotal - (Twenty_One_Game.GetNumOfUserAcesWithValueOne() * decrementScoreBy);
            //changes totals to strings and change label text to totals
            dPointsLabel.Text = dealerTotal.ToString();
            pPointsLabel.Text = userTotal.ToString();
            //makes points labels visible
            pPointsLabel.Visible = true;
            dPointsLabel.Visible = true;
        }//end dealButton
コード例 #6
0
        /// <summary>
        /// Deals one card to player and plays for dealer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            Hand newCardPlayer = Twenty_One_Game.GetHand(Twenty_One_Game.PLAYER);

            checkAce();
            Twenty_One_Game.PlayForDealer();
            DisplayGuiHand(newCardPlayer, tableLayoutPanel2);
            ppoints.Text = String.Format("{0}", Twenty_One_Game.CalculateHandTotal(Twenty_One_Game.PLAYER));

            /// <summary>
            /// Checked if dealer or player have busted and who won
            /// </summary>
            if (Twenty_One_Game.GetTotalPoints(Twenty_One_Game.DEALER) > 16 &&
                (Twenty_One_Game.GetTotalPoints(Twenty_One_Game.DEALER) > (Twenty_One_Game.GetTotalPoints(Twenty_One_Game.PLAYER)) &&
                 (Twenty_One_Game.GetTotalPoints(Twenty_One_Game.PLAYER)) < 22))
            {
                hosuescore++;
                endScoreH.Text = hosuescore.ToString();
            }
            else if (Twenty_One_Game.GetTotalPoints(Twenty_One_Game.PLAYER) > 17 &&
                     (Twenty_One_Game.GetTotalPoints(Twenty_One_Game.PLAYER) > (Twenty_One_Game.GetTotalPoints(Twenty_One_Game.DEALER)) &&
                      (Twenty_One_Game.GetTotalPoints(Twenty_One_Game.PLAYER)) < 22))
            {
                playerscore++;
                endScoreP.Text = playerscore.ToString();
            }

            if (Twenty_One_Game.GetTotalPoints(Twenty_One_Game.PLAYER) > 21)
            {
                busted2.Visible = true;
                hit.Enabled     = false;
                stand.Enabled   = false;
                if (stand.Enabled == false)
                {
                    hosuescore++;
                    endScoreH.Text = hosuescore.ToString();
                }
            }
            if (Twenty_One_Game.GetTotalPoints(Twenty_One_Game.DEALER) > 21)
            {
                hpoints.Visible = true;
                hit.Enabled     = false;
                stand.Enabled   = false;
                if (stand.Enabled == false)
                {
                    hosuescore++;
                    endScoreH.Text = hosuescore.ToString();
                }
            }
        }
コード例 #7
0
ファイル: Twenty_one.cs プロジェクト: I3un/CAB201
        private void dealButton_Click(object sender, EventArgs e) {
            Twenty_One_Game.SetUpGame();
            dealerBustedLabel.Visible = false;
            playerbustedLabel.Visible = false;
            second_turn = 1;
            Twenty_One_Game.DealOneCardTo(FIRST_PLAYER);
            if (Twenty_One_Game.GetHand(FIRST_PLAYER).GetCard(0).GetFaceValue() == FaceValue.Ace) {
                DialogResult result = MessageBox.Show("Do you want Ace to be a 1?", //The question.
                                "Ace", // The MessageBox's caption.
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question);
                if (result == DialogResult.Yes) {
                    Twenty_One_Game.IncrementNumOfUserAcesWithValueOne();
                } else {
                    //nothing
                }
            }

            Twenty_One_Game.DealOneCardTo(FIRST_PLAYER);
            if (Twenty_One_Game.GetHand(FIRST_PLAYER).GetCard(1).GetFaceValue() == FaceValue.Ace) {
                DialogResult result = MessageBox.Show("Do you want Ace to be a 1?", //The question.
                                "Ace", // The MessageBox's caption.
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question);
                if (result == DialogResult.Yes) {
                    Twenty_One_Game.IncrementNumOfUserAcesWithValueOne();
                } else {
                    //nothing
                }
            }

            Twenty_One_Game.DealOneCardTo(COMPUTER);
            Twenty_One_Game.DealOneCardTo(COMPUTER);

            DisplayGuiHand(Twenty_One_Game.GetHand(COMPUTER), topTableLayoutPanel);
            DisplayGuiHand(Twenty_One_Game.GetHand(FIRST_PLAYER), bottomTableLayoutPanel);

            Twenty_One_Game.CalculateHandTotal(FIRST_PLAYER);
            Twenty_One_Game.CalculateHandTotal(COMPUTER);

            ace_NumberLabel.Text = Twenty_One_Game.GetNumOfUserAcesWithValueOne().ToString();
            pointDealerLabel.Text = Twenty_One_Game.GetTotalPoints(COMPUTER).ToString();
            pointPlayerLabel.Text = Twenty_One_Game.GetTotalPoints(FIRST_PLAYER).ToString();

            dealButton.Enabled = false;
            hitButton.Enabled = true;
            standButton.Enabled = true;
        }
コード例 #8
0
        }//end dealButton

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void hitButton_Click(object sender, EventArgs e)
        {
            int userTotal;
            int decrementScoreBy = 10;

            Card card = Twenty_One_Game.DealOneCardTo(1);                     //deals one card to user

            DisplayGuiHand(Twenty_One_Game.GetHand(1), userTableLayoutPanel); //display users hand
            userTotal = Twenty_One_Game.CalculateHandTotal(1);                //calculate adjusted user total
            //decrement user total by ace decrement value if user responded yes

            if (card.GetFaceValue() == FaceValue.Ace)
            {
                //show messagebox asking user if they want to count their ace as one
                DialogResult dialogResult = MessageBox.Show("Count Ace as 1?", "You got an Ace!", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    //updates number of user aces with value 1 and appropriate label
                    Twenty_One_Game.IncrementNumofUserAcesWithValueOne();
                    aceLabel.Text = Twenty_One_Game.GetNumOfUserAcesWithValueOne().ToString();
                } //end nested if
            }     //end if


            userTotal = userTotal - (Twenty_One_Game.GetNumOfUserAcesWithValueOne() * decrementScoreBy);
            //changes usertotal to a string and change points label text to total
            pPointsLabel.Text = userTotal.ToString();

            if (userTotal <= 21)
            {
                //sets bust labels to not visible and hitbutton to enabled while the user keeps playing
                pBust.Visible     = false;
                hitButton.Enabled = true;
            }
            else
            {
                //if total is greater than 21, sets bust label to visible, disables play and stand buttons and enables deal button
                pBust.Visible       = true;
                hitButton.Enabled   = false;
                standButton.Enabled = false;
                dealButton.Enabled  = true;
                //increments dealers games won total and updates appropriate label to show the new score
                Twenty_One_Game.IncrementGamesWon(0);
                dGamesLabel.Text = Twenty_One_Game.GetNumOfGamesWon(0).ToString();
                Twenty_One_Game.ResetTotals();
            } //end if-else
        }     //end hitButton
コード例 #9
0
        }     //end DisplayGuiHand

        /// <summary>
        /// Sets up the GUI to continue if previous game was canceled.
        /// </summary>
        private void InitGui()
        {
            if (Twenty_One_Game.Continue())
            {
                int userTotal        = 0;
                int compTotal        = 0;
                int decrementScoreBy = 10;
                dealButton.Enabled   = false;
                hitButton.Enabled    = true;
                standButton.Enabled  = true;
                userTotal            = Twenty_One_Game.CalculateHandTotal(1);
                compTotal            = Twenty_One_Game.CalculateHandTotal(0);
                userTotal            = userTotal - (Twenty_One_Game.GetNumOfUserAcesWithValueOne() * decrementScoreBy);
                pPointsLabel.Text    = userTotal.ToString();
                dPointsLabel.Text    = compTotal.ToString();
                pPointsLabel.Visible = true;
                dPointsLabel.Visible = true;
                aceLabel.Text        = Twenty_One_Game.GetNumOfUserAcesWithValueOne().ToString();
            } // end if
        }     // end initGui
コード例 #10
0
        }     //end hitButton

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void standButton_Click(object sender, EventArgs e)
        {
            hitButton.Enabled   = false;
            standButton.Enabled = false;
            int dealerTotal = Twenty_One_Game.GetTotalPoints(0);
            int userTotal   = Twenty_One_Game.GetTotalPoints(1);

            // gets the user total from the GUI to avoid ace bug
            int.TryParse(pPointsLabel.Text, out userTotal);

            //while the dealer total is less than the user total and less than 21, keeping dealing cards to dealer
            while ((dealerTotal < 21) && (userTotal > dealerTotal))
            {
                Twenty_One_Game.PlayForDealer();
                dealerTotal = Twenty_One_Game.CalculateHandTotal(0);
                DisplayGuiHand(Twenty_One_Game.GetHand(0), dealerTableLayoutPanel);
                dPointsLabel.Text = dealerTotal.ToString();
            }

            if (dealerTotal > 21)
            {
                Twenty_One_Game.IncrementGamesWon(1);                                //adds a point to the users score
                pGamesLabel.Text   = Twenty_One_Game.GetNumOfGamesWon(1).ToString(); //outputs a new score to form
                dBust.Visible      = true;
                dealButton.Enabled = true;
                Twenty_One_Game.ResetTotals();
            }
            else if (dealerTotal > userTotal)
            {
                Twenty_One_Game.IncrementGamesWon(0);                                //adds a point to the dealers score
                dGamesLabel.Text   = Twenty_One_Game.GetNumOfGamesWon(0).ToString(); //outputs new score to form
                dealButton.Enabled = true;
                Twenty_One_Game.ResetTotals();
            }
            else if (dealerTotal == userTotal)
            {
                MessageBox.Show("It was a Tie");
                dealButton.Enabled = true;
                Twenty_One_Game.ResetTotals();
            } //end if-else
        }     //end standButton
コード例 #11
0
        }// end DisplayGuiHand

        /// <summary>
        /// Checks the players hand for an Ace. Calls DetermineAceValue to
        /// prompt player to decide whether they want the Ace to have the value one
        /// </summary>
        private void CheckPlayerHandForAce()
        {
            Hand hand = Twenty_One_Game.GetHand(PLAYER);

            // Checks entire hand for Ace
            if (hand.GetCount() <= NUM_INITIAL_CARDS)
            {
                foreach (Card card in hand)
                {
                    if (card.GetFaceValue() == FaceValue.Ace)
                    {
                        // Ask user what value the want the Ace to be
                        DetermineAceValue();

                        // Update hand calculation
                        Twenty_One_Game.CalculateHandTotal(PLAYER);

                        // Update displayed hand total
                        DisplayPoints();
                    }
                }
            }
            else
            {
                // Checks the last drawn card for an Ace
                if (hand.GetCard(hand.GetCount() - 1).GetFaceValue() == FaceValue.Ace)
                {
                    // Ask user what value the want the Ace to be
                    DetermineAceValue();

                    // Update hand calculation
                    Twenty_One_Game.CalculateHandTotal(PLAYER);

                    // Update displayed hand total
                    DisplayPoints();
                }
            }
        }// end CheckPlayerHandForAce
コード例 #12
0
        } // end btnDeal_Click

        private void btnHit_Click(object sender, EventArgs e)
        {
            bool busted;

            Twenty_One_Game.DealOneCardTo(PLAYER);

            // Display players hand
            DisplayGuiHand(Twenty_One_Game.GetHand(PLAYER), tblPanelPlayer);

            // If Ace drawn - prompt user for value
            CheckPlayerHandForAce();

            // Recalculate totals for player after each new card hit
            Twenty_One_Game.CalculateHandTotal(PLAYER);

            // Update points disply to reflect new calculation
            DisplayPoints();

            // Test if player busted message should be displayed on each new hit
            busted = DetermineIfPlayerBusted(PLAYER);

            if (busted)
            {
                // Reset for next game
                DisableHitButton();
                DisableStandButton();
                EnableDealButton();
                // Update Games won totals on player bust
                DisplayGamesWon();
            }
            else
            {
                // Continue game
                EnableHitButton();
                EnableStandButton();
            }
        } // end btnHit_Click
コード例 #13
0
        }// End DisplayGuiHand

        /// <summary>
        /// Deals 2 card for plays and Deaker
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            Two_Up_Game.SetUpGame();
            hit.Enabled   = true;
            stand.Enabled = true;
            Twenty_One_Game.SetUpGame();
            busted1.Visible = false;
            busted2.Visible = false;
            Twenty_One_Game.DealOneCardTo(Twenty_One_Game.DEALER);
            Twenty_One_Game.DealOneCardTo(Twenty_One_Game.DEALER);
            Twenty_One_Game.DealOneCardTo(Twenty_One_Game.PLAYER);
            Twenty_One_Game.DealOneCardTo(Twenty_One_Game.PLAYER);
            hit.Enabled   = true;
            stand.Enabled = true;

            Hand HandForPlayer = Twenty_One_Game.GetHand(Twenty_One_Game.PLAYER);
            Hand HandForDealer = Twenty_One_Game.GetHand(Twenty_One_Game.DEALER);

            Twenty_One_Game.CalculateHandTotal(Twenty_One_Game.PLAYER);
            ppoints.Text = String.Format("{0}", Twenty_One_Game.GetTotalPoints(Twenty_One_Game.PLAYER));
            hpoints.Text = String.Format("{0}", Twenty_One_Game.CalculateHandTotal(Twenty_One_Game.DEALER));
            DisplayGuiHand(HandForDealer, tableLayoutPanel1);
            DisplayGuiHand(HandForPlayer, tableLayoutPanel2);
        }
コード例 #14
0
        private void Stand_button_Click(object sender, EventArgs e)
        {
            int dealer_points = Twenty_One_Game.CalculateHandTotal(0);
            int player_points = Twenty_One_Game.CalculateHandTotal(1);

            show_points(dealer_points, player_points);


            while (dealer_points < 17)
            {
                Twenty_One_Game.DealOneCardTo(0);
                DisplayGuiHand(Twenty_One_Game.GetHand(0), dealerTableLayoutPanel);
                DisplayGuiHand(Twenty_One_Game.GetHand(1), playerTableLayoutPanel);

                dealer_points = Twenty_One_Game.CalculateHandTotal(0);
                show_points(dealer_points, player_points);
                check_if_dealer_points_exceeds_limit(dealer_points);
            }

            if (dealer_points < 21)
            {
                decide_the_winner(dealer_points, player_points);
            }
        }