/// <summary> /// Present the user with the results when they decide to cancel the game and close the window. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cancelButton_Click(object sender, EventArgs e) { int dealerGamesWon = TwentyOneGame.GetNumOfGamesWon(DEALER); int playerGamesWon = TwentyOneGame.GetNumOfGamesWon(PLAYER); if (dealerGamesWon > playerGamesWon) { Program.showOKMessageBox("House won. Better luck next time."); } else if (playerGamesWon > dealerGamesWon) { Program.showOKMessageBox("You won! Well done."); } else { Program.showOKMessageBox("It was a draw!"); } TwentyOneGame.ResetTotals(); this.Close(); }
} //end of StandButton_Click private void CancelButton_Click(object sender, EventArgs e) { //Reset totals. TwentyOneGame.ResetTotals(); //If player and dealer has the same amount of games won. if (TwentyOneGame.GetNumOfGamesWon(0) == TwentyOneGame.GetNumOfGamesWon(1)) { MessageBox.Show("It was a draw!"); } //If dealer has less games won than players show player won message. else if (TwentyOneGame.GetNumOfGamesWon(0) > TwentyOneGame.GetNumOfGamesWon(1)) { MessageBox.Show("House won! Better luck next time!"); } //Otherwise show house won message. else { MessageBox.Show("You won! Well done."); }//end if //Close window. this.Close(); }//end of CancelButton_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
public TwentyOne_Game_Form() { InitializeComponent(); TwentyOneGame.SetUpGame(); TwentyOneGame.ResetTotals(); }//end of TwentyOne_Game_Form