private void Lockbetbutton_Click(object sender, EventArgs e) { if (int.Parse(bets.SelectedIndex.ToString()) < PlayerBalance) { bets.Enabled = false; } else { MessageBox.Show("You can't bet more than you have"); return; } lockedbet = true; playerbet = int.Parse(bets.SelectedItem.ToString()); PlayerBalance -= playerbet; Newgame.Enabled = false; NewGameMethod(); if (thePlayer.HardHandValue == 21 || thePlayer.SoftHandValue == 21 && !insurance) { MessageBox.Show("You have Blackjack!"); PlayerBalance += (int)(playerbet * 2.5); bets.SelectedIndex = 0; HitButton.Enabled = false; StandButton.Enabled = false; Newgame.Enabled = true; _ = Newgame.Focus(); } else { Lockbetbutton.Enabled = false; } }
private void hit_Click(object sender, EventArgs e) { if (Insurancebutton.Visible) { insuranceamountbox.Text = "0"; insuranceamountbox.Enabled = false; Insurancebutton.Enabled = false; } Newgame.Enabled = true; if (!lockedbet) { MessageBox.Show("You have not placed your bet. Bet and then try again."); return; } PlayerBalanceLabel.Text = string.Format("Your balance is {0}", PlayerBalance.ToString("C0")); if ((Playercardvisible < 7) && (thePlayer.HardHandValue < 21)) { //players new card is displayed Playercards[Playercardvisible].Visible = true; //player draws card, adds value to HardHandValue, and card to hand. Playercards[Playercardvisible].Image = thePlayer.playerhit().CardFront(); Playercardvisible++; //assign card image to picturebox } else if (Playercardvisible >= 7) { MessageBox.Show("You have the max number of cards in hand.\nYou must stand."); } if (thePlayer.HardHandValue > 21) { MessageBox.Show("The player has busted!"); playerbet = 0; bets.SelectedIndex = 0; HitButton.Enabled = false; StandButton.Enabled = false; _ = Newgame.Focus(); if (PlayerBalance < 5) { MessageBox.Show("You are unable to make the minimum bet and must make room for another player.\nGoodbye."); } } else if (thePlayer.HardHandValue == 21 || thePlayer.SoftHandValue == 21) { MessageBox.Show("You have 21!"); PlayerBalance += (int)(playerbet * 2.5); bets.SelectedIndex = 0; HitButton.Enabled = false; StandButton.Enabled = false; _ = Newgame.Focus(); } PlayerBalanceLabel.Text = string.Format("Your balance is {0}", PlayerBalance.ToString("C0")); }
private void Insurancebutton_Click(object sender, EventArgs e) { insurancebet = int.Parse(insuranceamountbox.Text); if (insurancebet == 0) { MessageBox.Show("You must place a minimum bet of $1"); return; } if (insurancebet > (playerbet / 2)) { insurancebet = playerbet / 2; } insuranceamountbox.Text = insurancebet.ToString(); PlayerBalance -= insurancebet; PlayerBalanceLabel.Text = string.Format("Your balance is {0}", PlayerBalance.ToString("C0")); Card temp = theDealer.getonedealercard(); if (temp.Face == 10 || temp.ValueOf == 10) { Dealercards[Dealercardvisible].Image = theDealer.getdealerslastcard().CardFront(); MessageBox.Show("The dealer has Blackjack. You get your insurance payout"); PlayerBalance += insurancebet * 2; PlayerBalanceLabel.Text = string.Format("Your balance is {0}", PlayerBalance.ToString("C0")); Newgame.Enabled = true; } else { MessageBox.Show("The dealer does not have Blackjack. You lose your insurance."); HitButton.Enabled = true; StandButton.Enabled = true; HitButton.Enabled = true; } if (thePlayer.SoftHandValue == 21 && insurance) { MessageBox.Show("Push. You get your main bet back"); PlayerBalance += playerbet; } if (thePlayer.HardHandValue == 21 || thePlayer.SoftHandValue == 21 && !insurance) { MessageBox.Show("You have Blackjack!"); PlayerBalance += (int)(playerbet * 2.5); bets.SelectedIndex = 0; HitButton.Enabled = false; StandButton.Enabled = false; Newgame.Enabled = true; _ = Newgame.Focus(); } }
private void stand_Click(object sender, EventArgs e) { if (Insurancebutton.Visible) { insuranceamountbox.Text = "0"; insuranceamountbox.Enabled = false; Insurancebutton.Enabled = false; } if (!lockedbet) { MessageBox.Show("You have not placed your bet. Bet and then try again."); return; } //player chooses to stand. Start dealer functions if (insurance) { Dealercards[Dealercardvisible].Image = theDealer.getdealerslastcard().CardFront(); } while (!isgameover) { theDealer.dealeraction(thePlayer.HardHandValue, playerbet); Dealercards[Dealercardvisible].Visible = true; Dealercards[Dealercardvisible].Image = theDealer.getdealerslastcard().CardFront(); Dealercardvisible++; if (theDealer.handvalue < 17) { continue; } else { isgameover = true; } } //Use soft hand value if hand has ace and is better than hardhand value if (thePlayer.SoftHandValue > thePlayer.HardHandValue && thePlayer.SoftHandValue <= 21) { thePlayer.HardHandValue = thePlayer.SoftHandValue; } //compare player and dealer hands if (theDealer.handvalue > 21) { MessageBox.Show("The dealer has busted.\nPlayer wins."); PlayerBalance += (playerbet * 2); } else if (theDealer.handvalue == thePlayer.HardHandValue) { //print push/tie game MessageBox.Show(string.Format("Push. You get your bet of ${0} back.", playerbet)); //return player bet PlayerBalance += playerbet; //exit } else if (theDealer.handvalue > thePlayer.HardHandValue) { //print dealer wins MessageBox.Show(string.Format("Dealer Wins! You lost ${0}", playerbet)); //exit } else if (theDealer.handvalue < thePlayer.HardHandValue) {//print player wins MessageBox.Show(string.Format("Player Wins! You win ${0}!", playerbet)); //add bet to player balance PlayerBalance += (2 * playerbet); //exit } PlayerBalanceLabel.Text = string.Format("Your balance is {0}", PlayerBalance.ToString("C0")); if (PlayerBalance < 5) { MessageBox.Show(string.Format("You have {0} unable to make the minimum bet and must make room for another player.\nGoodbye.", PlayerBalance.ToString("C0"))); } HitButton.Enabled = false; StandButton.Enabled = false; Newgame.Enabled = true; _ = Newgame.Focus(); isgameover = false; }