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); }
}// end DetermineAceValue /// <summary> /// Displays the total points from the Game class in the GUI for each player /// </summary> private void DisplayPoints() { for (int i = 0; i < Twenty_One_Game.NUM_OF_PLAYERS; i++) { pointsLabels[i].Text = Twenty_One_Game.GetTotalPoints(i).ToString(); } }// end DisplayPoints
}// end DisplayPoints /// <summary> /// Displays the total games won from the Game class in the GUI for each player /// </summary> private void DisplayGamesWon() { for (int i = 0; i < Twenty_One_Game.NUM_OF_PLAYERS; i++) { gamesWonLabels[i].Text = Twenty_One_Game.GetNumOfGamesWon(i).ToString(); } }// end DisplayGamesWon
}// end AutomaticDealerBust /// <summary> /// Display exit score summary message depending upon scores /// </summary> private void ExitGameSummary() { string message; int dealerScore, playerScore; dealerScore = Twenty_One_Game.GetNumOfGamesWon(DEALER); playerScore = Twenty_One_Game.GetNumOfGamesWon(PLAYER); // determine message to display on exit if (dealerScore > playerScore) { message = "House Won. Better luck next time!"; } else if (playerScore > dealerScore) { message = "You won. Well done!"; } else { message = "It was a draw!"; } // output message via MessageBox MessageBox.Show(message); }// end ExitGameSummary
private void win(int a) { if (a == 0) { BUSTED_DEALER_label.Visible = false; BUSTED_PLAYER_label.Visible = true; Twenty_One_Game.numOfGamesWon[0] = Twenty_One_Game.numOfGamesWon[0] + 1; label2.Text = Twenty_One_Game.GetNumOfGamesWon(0).ToString(); MessageBox.Show("House won! Better luck next time."); } else if (a == 1) { BUSTED_DEALER_label.Visible = true; BUSTED_PLAYER_label.Visible = false; Twenty_One_Game.numOfGamesWon[1] = Twenty_One_Game.numOfGamesWon[1] + 1; label4.Text = Twenty_One_Game.GetNumOfGamesWon(1).ToString(); MessageBox.Show("Player 1 won! Better luck next time."); } else { MessageBox.Show("It is a draw"); } Twenty_One_Game.SetUpGame(); this.Deal_button.Enabled = true; this.Hit_button.Enabled = false; this.Stand_button.Enabled = false; this.BUSTED_DEALER_label.Visible = false; this.BUSTED_PLAYER_label.Visible = false; i = 1; }
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
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; } }
public Twenty_one() { InitializeComponent(); Twenty_One_Game.SetUpGame(); hitButton.Enabled = false; testButton.Enabled = false; standButton.Enabled = false; dealerBustedLabel.Visible = false; playerbustedLabel.Visible = false; }
/// <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(); }
}// end btnStand_Click private void btnCancel_Click(object sender, EventArgs e) { //Display exit summary ExitGameSummary(); // Reset totals so another set of games can be played Twenty_One_Game.ResetTotals(); Close(); }// end btnCancel_Click
}//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
/// <summary> /// Checked if dealer or player have busted /// </summary> private void checkAce() { Card card = Twenty_One_Game.DealOneCardTo(Twenty_One_Game.PLAYER); //Twenty_One_Game.CalculateHandTotal(Twenty_One_Game.0); if (card.GetFaceValue().Equals(FaceValue.Ace)) { DialogResult dialogResult = MessageBox.Show("Count Ace as one?", "", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { Twenty_One_Game.GetNumOfUserAcesWithValueOne(); } } }
/// <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(); } } }
}// end DisplayAcesValueOne /// <summary> /// Determines if the player or dealer has busted and shows busted label accordingly /// </summary> /// <param name="person">Index of person in points array of Game class. 0 for PLAYER. 1 for DEALER</param> /// <returns></returns> private bool DetermineIfPlayerBusted(int person) { int score; score = Twenty_One_Game.GetTotalPoints(person); if (score > WIN) { bustedLabels[person].Visible = true; return(true); } else { return(false); } }// end DetermineIfPlayerBusted
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; }
}//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
} // end initGui /*// <summary> * /// Test button event handler * /// </summary> * /// <param name="sender"></param> * /// <param name="e"></param> * private void testButton_Click(object sender, EventArgs e) { * const int testNumOfCardsForDealer = 2; * const int testNumOfCardsForPlayer = 8; * CardPile testCardPile = new CardPile(true); * testCardPile.Shuffle(); * Hand testHandForDealer = new Hand(testCardPile.DealCards(testNumOfCardsForDealer)); * Hand testHandForPlayer = new Hand(testCardPile.DealCards(testNumOfCardsForPlayer)); * DisplayGuiHand(testHandForDealer, dealerTableLayoutPanel); * DisplayGuiHand(testHandForPlayer, userTableLayoutPanel); * }//end testButton*/ /// <summary> /// Displays a message to the user and closes the form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cancelButton_Click(object sender, EventArgs e) { if (Twenty_One_Game.GetNumOfGamesWon(0) < Twenty_One_Game.GetNumOfGamesWon(1)) { MessageBox.Show("Congratulations you won, " + Twenty_One_Game.GetNumOfGamesWon(1) + " to " + Twenty_One_Game.GetNumOfGamesWon(0) + "."); } else if (Twenty_One_Game.GetNumOfGamesWon(1) < Twenty_One_Game.GetNumOfGamesWon(0)) { MessageBox.Show("Sorry you lost, " + Twenty_One_Game.GetNumOfGamesWon(0) + " to " + Twenty_One_Game.GetNumOfGamesWon(1) + "."); } else { MessageBox.Show("Scores were tied, " + Twenty_One_Game.GetNumOfGamesWon(0) + " to " + Twenty_One_Game.GetNumOfGamesWon(1) + "."); } //Twenty_One_Game.ResetTotals(); this.Close(); }//end cancelButton
}// end CheckPlayerHandForAce /// <summary> /// Message box to prompt the player what value they want for the Aces /// Calls IncrementNumOfUserAcesWithValueOne() in Game class to update number of Aces with value 1 /// </summary> public void DetermineAceValue() { string message = "Count Ace as one?"; string caption = "You got an Ace!"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result = MessageBox.Show(message, caption, buttons); if (result == DialogResult.Yes) { // Increments number of Aces with value 1 Twenty_One_Game.IncrementNumOfUserAcesWithValueOne(); // Update displayed total to reflect decision DisplayAcesValueOne(); } }// end DetermineAceValue
} //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
} //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
} // end btnHit_Click private void btnStand_Click(object sender, EventArgs e) { // Play dealer turn Twenty_One_Game.PlayForDealer(); // Display dealers hand DisplayGuiHand(Twenty_One_Game.GetHand(DEALER), tblPanelDealer); // Display total of dealers hand DisplayPoints(); // Update display of hand total DisplayGamesWon(); // Determine if busted message should be displayed DetermineIfPlayerBusted(DEALER); // Reset for next game DisableHitButton(); DisableStandButton(); EnableDealButton(); }// end btnStand_Click
}// 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
} // 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
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); } }
public Twenty_One() { InitializeComponent(); //testButton.Visible = false; // Re-show scores from previous games dGamesLabel.Text = Twenty_One_Game.GetNumOfGamesWon(0).ToString(); pGamesLabel.Text = Twenty_One_Game.GetNumOfGamesWon(1).ToString(); DisplayGuiHand(Twenty_One_Game.GetHand(0), dealerTableLayoutPanel); DisplayGuiHand(Twenty_One_Game.GetHand(1), userTableLayoutPanel); //ensures bust labels and points labels aren't visible at the start of a game pBust.Visible = false; dBust.Visible = false; pPointsLabel.Visible = false; dPointsLabel.Visible = false; //ensures the hit and stand button are not enabled before cards are dealt hitButton.Enabled = false; standButton.Enabled = false; //sets game up, initializing variables //Twenty_One_Game.SetUpGame(); //code given in the assignment tableLayoutPanels = new TableLayoutPanel[Twenty_One_Game.NUM_OF_PLAYERS] { userTableLayoutPanel, dealerTableLayoutPanel }; bustedLabels = new Label[Twenty_One_Game.NUM_OF_PLAYERS] { pBust, dBust }; pointsLabels = new Label[Twenty_One_Game.NUM_OF_PLAYERS] { pPointsLabel, dPointsLabel }; gamesWonLabels = new Label[Twenty_One_Game.NUM_OF_PLAYERS] { pGamesLabel, dGamesLabel }; InitGui(); }//end Twenty_One form constructor
}// 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); }
}// end DisplayGamesWon /// <summary> /// Displays the total number of Aces with value 1 from the Game class in the GUI for player /// </summary> private void DisplayAcesValueOne() { lblNumberAcesValueOne.Text = Twenty_One_Game.GetNumOfUserAcesWithValueOfOne().ToString(); }// end DisplayAcesValueOne
public Which_Card_Game() { InitializeComponent(); Twenty_One_Game.SetUpGame(); }//end Which_Card_Game