} //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
} //end of HitButton_Click private void StandButton_Click(object sender, EventArgs e) { //While Dealer's points are under 17.. while (TwentyOneGame.GetTotalPoints(0) < 17) { //Dealer plays. TwentyOneGame.PlayForDealer(); //Updates points. PointsLabel1.Text = TwentyOneGame.GetTotalPoints(0).ToString(); //Updates GUI. DisplayGuiHand(TwentyOneGame.GetHand(0), LayoutPanel1); } //Disables Stand and Hit button and enables DealButton. StandButton.Enabled = false; HitButton.Enabled = false; DealButton.Enabled = true; //If Dealer's points are over 21.. if (TwentyOneGame.GetTotalPoints(0) > 21) { //Show BUSTED Label BustedLabel1.Visible = true; //Updates Games won of player. Number2.Text = TwentyOneGame.GetNumOfGamesWon(1).ToString(); } else { //Otherwise dealer plays TwentyOneGame.PlayForDealer(); //Updates Games won. Number1.Text = TwentyOneGame.GetNumOfGamesWon(0).ToString(); Number2.Text = TwentyOneGame.GetNumOfGamesWon(1).ToString(); } //end of if statement } //end of StandButton_Click
}//end of DisplayGuiHand private void DealButton_Click(object sender, EventArgs e) { //Hides the BUSTED labels. BustedLabel1.Visible = false; BustedLabel2.Visible = false; //Resets Totals. TwentyOneGame.ResetTotals(); //Updates the Points text. PointsLabel2.Text = TwentyOneGame.GetTotalPoints(1).ToString(); PointsLabel1.Text = TwentyOneGame.GetTotalPoints(0).ToString(); //Updates the Amount of Aces that are considered as one. AmountOfAcesAsOne.Text = TwentyOneGame.GetNumOfUserAcesWithValueOne().ToString(); //Gets the cards from the player's hand. Hand players_hand = TwentyOneGame.GetHand(1); //Updates GUI panels. DisplayGuiHand(TwentyOneGame.GetHand(0), LayoutPanel1); DisplayGuiHand(TwentyOneGame.GetHand(1), LayoutPanel2); //Find the Aces in the cards. foreach (Card card in players_hand) { if (card.GetFaceValue() == FaceValue.Ace) { DialogResult choice = MessageBox.Show("Count Ace as 1?", "You got an Ace!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (choice == DialogResult.Yes) { TwentyOneGame.IncrementNumOfUserAcesWithValueOne(); AmountOfAcesAsOne.Text = TwentyOneGame.GetNumOfUserAcesWithValueOne().ToString(); } //end of if statement } //end of if statement } //end of foreach loop //Calculates totals. TwentyOneGame.CalculateHandTotal(0); TwentyOneGame.CalculateHandTotal(1); //Updates Totals. PointsLabel2.Text = TwentyOneGame.GetTotalPoints(1).ToString(); PointsLabel1.Text = TwentyOneGame.GetTotalPoints(0).ToString(); //If dealer goes over 21 points.. if (TwentyOneGame.GetTotalPoints(0) > 21) { //Show BUSTED label. BustedLabel1.Visible = true; //Updates number of games won. Number2.Text = TwentyOneGame.GetNumOfGamesWon(1).ToString(); //If player goes over 21 points.. } else if (TwentyOneGame.GetTotalPoints(1) > 21) { //Show BUSTED label. BustedLabel2.Visible = true; //Updates number of games won. Number1.Text = TwentyOneGame.GetNumOfGamesWon(0).ToString(); } else { //Disable DealButton when already dealt and enable Hit and Stand buttons. DealButton.Enabled = false; HitButton.Enabled = true; StandButton.Enabled = true; } //end of if statement } //end of DealButton_Click