// Player doubles bet and draws 1 more card private void Double_Button_Click(object sender, EventArgs e) { Doubled_Previous_Hand = true; Current_Bet *= 2; //Console.WriteLine("Double Button Click: " + Current_Bet); Bet_TextBox.Text = string.Format("{0:0.00}", Current_Bet); if (!d.Is_Empty()) { Card c = d.Draw(); Player_Card_3.Image = c.Get_Image(); // Check for ace if (Player_Result_TextBox.Text.Contains('/')) { // check for 21 if (Player_Current_Total + 11 == 21) { Player_Current_Total = 21; Player_Result_TextBox.Text = "21"; Stand_Button.PerformClick(); } //no 21 - perform calculation with ace in hand else { int Possible_Value_1 = Player_Current_Total + c.Get_Integer_Value(); int Possible_Value_2 = Possible_Value_1 + 10; Player_Current_Total = Possible_Value_1; Player_Result_TextBox.Text = Possible_Value_1.ToString() + "/" + Possible_Value_2.ToString(); Player_Hand_Count++; // end hand if player busts and reveal dealer card if (Player_Current_Total > 21) { Dealer_Card_1.Image = Dealer_Down_Card.Get_Image(); // Dealer results not calculated since player busted Decision(true, false, false, false); return; } } } else { Player_Current_Total += c.Get_Integer_Value(); Player_Result_TextBox.Text = Player_Current_Total.ToString(); Player_Hand_Count++; // end hand if player busts and reveal dealer card if (Player_Current_Total > 21) { Dealer_Card_1.Image = Dealer_Down_Card.Get_Image(); // Dealer results not calculated since player busted Decision(true, false, false, false); return; } } } // empty shoe else { Display_Empty_Message(); return; } // reduce current bet from double amount //Console.WriteLine("div"); //Current_Bet /= 2; }
private void Stand_Button_Click(object sender, EventArgs e) { Player_Turn = false; // ====================== int Possible_Value_1 = 0; // Assigned when an ace is present int Possible_Value_2 = 0; // // ====================== Dealer_Card_1.Image = Dealer_Down_Card.Get_Image(); Dealer_Current_Total += Dealer_Down_Card.Get_Integer_Value(); // check for face down ace if (Dealer_Down_Card.Get_Integer_Value() == 1) { Dealer_Ace = true; string Possible_Sums = ""; Possible_Value_1 = Dealer_Current_Total; Possible_Value_2 = Dealer_Current_Total + 10; Dealer_Current_Total = Possible_Value_1; Possible_Sums += Possible_Value_1.ToString() + "/" + Possible_Value_2.ToString(); Dealer_Result_TextBox.Text = Possible_Sums; } // else if 2nd card is ACE else if (Dealer_Result_TextBox.Text.Equals("1/11")) { Possible_Value_1 = Dealer_Current_Total; Possible_Value_2 = Dealer_Current_Total + 10; //Console.WriteLine(Possible_Value_1 + " " + Possible_Value_2); //Check for soft18+ if (Possible_Value_2 > 17 && Possible_Value_2 < 22) { Dealer_Current_Total = Possible_Value_2; Dealer_Result_TextBox.Text = Dealer_Current_Total.ToString(); Decision(); return; // not tested yet } } else { Dealer_Result_TextBox.Text = Dealer_Current_Total.ToString(); } //Console.WriteLine(Dealer_Current_Total); // Dealer keeps drawing until passes 21 while (Dealer_Current_Total < 17) // 17 { // Console.WriteLine("424"); // Check for soft18+ before drawing 3rd card if ((Dealer_Ace) && (Dealer_Current_Total + 10 > 17) && (Dealer_Current_Total < 22)) { //Console.WriteLine(Dealer_Current_Total+10); Dealer_Current_Total += 10; Dealer_Ace = false; Decision(); return; // added 2:16 } else { if (!d.Is_Empty()) { Card c = d.Draw(); Remaining_Cards_Count_TextBox.Text = d.Get_Remaining_Cards().ToString(); if (Dealer_Hand_Count == 2) { Dealer_Card_3.Image = c.Get_Image(); } else if (Dealer_Hand_Count == 3) { Dealer_Card_4.Image = c.Get_Image(); } else if (Dealer_Hand_Count == 4) { Dealer_Card_5.Image = c.Get_Image(); } else if (Dealer_Hand_Count == 5) { Dealer_Card_6.Image = c.Get_Image(); } else if (Dealer_Hand_Count == 6) { Dealer_Card_7.Image = c.Get_Image(); } Dealer_Hand_Count++; Dealer_Current_Total += c.Get_Integer_Value(); Possible_Value_1 = Dealer_Current_Total; Possible_Value_2 = Possible_Value_1 + 10; // only display Possible_Value_1 if Value_2 is bust if (Possible_Value_2 > 21) { Dealer_Result_TextBox.Text = Possible_Value_1.ToString(); } // if Possible_Value_1 bust else if (Possible_Value_1 > 21) { Decision(false, true, false, false); return; // added 2:17 } // if dealer reached 21, go to decision else if (Possible_Value_1 == 21 || Possible_Value_2 == 21) { Decision(); return; // 5:02 } // dealer hits soft 17 else if (Possible_Value_1 == 17) { } // stand on soft 18+ else if (Possible_Value_2 > 17 && Possible_Value_2 < 22) { Dealer_Current_Total = Possible_Value_2; Dealer_Result_TextBox.Text = Dealer_Current_Total.ToString(); Decision(); return; // added 2:17 } } // empty shoe else { if (d.Get_Counter() == 0) { Display_Empty_Message(); } } } //Dealer_Result_TextBox.Text = Possible_Value_1.ToString() + "/" + Possible_Value_2.ToString(); } // Dealer bust if (Dealer_Current_Total > 21) { Decision(false, true, false, false); return; // added 2:17 } // Compare hands else { // Console.WriteLine("Player: " + Player_Result_TextBox.Text + "\r\nDealer: " + Dealer_Result_TextBox.Text); // Check for player ace //if (Player_Result_TextBox.Text.Contains('/')) if (Player_Ace) { Player_Current_Total += 10; Player_Result_TextBox.Text = Player_Current_Total.ToString(); } // Check for dealer ace if (Dealer_Result_TextBox.Text.Contains('/')) { //Dealer_Current_Total += 10; Dealer_Result_TextBox.Text = Dealer_Current_Total.ToString(); } //Console.WriteLine("THIS DECISION: 703"); Decision(); return; // added 2:17 } }
// Dealing of initial 4 cards. async private void Deal_Button_Click_1(object sender, EventArgs e) { Status_Label.Text = "Status: Round in Progress."; Decision_Reached = false; int Deal_Value = 0; Console.WriteLine("New hand ================================"); while (Deal_Value < 4) { if (!d.Is_Empty()) { Card c = d.Draw(); // Draw facedown on dealer's first turn if ((Dealer_Hand_Count == 0) && (!Player_Turn)) { Dealer_Down_Card = c; // If the facedown card is a 10, flag it if (Dealer_Down_Card.Get_Integer_Value() == 10) { Face_Down_Ten = true; } Dealer_Card_1.Image = c.Get_Image_FaceDown(); Dealer_Hand_Count++; Player_Turn = true; } else if (Player_Turn) { if (Player_Hand_Count == 0) { Player_Card_1.Image = c.Get_Image(); Player_First_Card = c.Get_Integer_Value(); } else if (Player_Hand_Count == 1) { Player_Card_2.Image = c.Get_Image(); Player_Second_Card = c.Get_Integer_Value(); // pause to display card await Task.Delay(DELAY_TASK_TIME); } // Check for ACE if (c.Get_Integer_Value() == 1) { //Console.WriteLine("WTF"); Player_Ace = true; // If first card is Ace if (Player_Hand_Count == 0) { Player_Current_Total += 1; Player_Result_TextBox.Text = "1/11"; } // Condition (A, A) - total will be 0 else if (Player_Current_Total == 0) { Player_Current_Total += 1; } // (x, A) condition else { Player_Current_Total += 1; } // Create string ex. (5/15) string Possible_Sums = ""; //Player_Current_Total += c.Get_Integer_Value(); Possible_Sums += Player_Current_Total.ToString() + "/" + (Player_Current_Total + 10).ToString(); Player_Result_TextBox.Text = Possible_Sums; // if BJ with (x, A) if ((Player_Current_Total + 10) == 21) { Decision(false, false, true, false); return; } // If soft 18+ - Stand else if (Player_Current_Total + 10 >= 18) { Console.WriteLine("236"); Player_Result_TextBox.Text = (Player_Current_Total + 10).ToString(); //Stand_Button.PerformClick(); premature stand: stand before dealer dealt his 2nd // instead of standing, just end player's turn Player_Turn = false; //return;// } } // (A, X) Condition else { //Console.WriteLine("214"); if (Player_Result_TextBox.Text.Contains('/')) { string Possible_Sums = ""; Player_Current_Total += c.Get_Integer_Value(); // BJ (A, 10) condition if ((Player_Current_Total + 10) == 21) { Player_Result_TextBox.Text = Player_Current_Total.ToString(); if (d.Is_Empty()) { // draw dealer's second card before calling Decision() to end turn; Dealer_Card_2.Image = d.Draw().Get_Image(); Decision(false, false, true, false); return; } // empty shoe else { Display_Empty_Message(); return; } //Clear_Button.PerformClick(); } Possible_Sums += Player_Current_Total.ToString() + "/" + (Player_Current_Total + 10).ToString(); Player_Result_TextBox.Text = Possible_Sums; } else { Player_Current_Total += c.Get_Integer_Value(); // (this value is calculated, this needs to be calculated) Player_Result_TextBox.Text = Player_Current_Total.ToString(); } } Player_Hand_Count++; Player_Turn = false; } // Dealer's turn else { if (Dealer_Hand_Count == 1) { Dealer_Card_2.Image = c.Get_Image(); } //Console.WriteLine("287: wtf is it doing"); // (-, A) Condition if (c.Get_Integer_Value() == 1) { // check for BJ outright //if (Dealer_Down_Card.Get_Integer_Value() + 11 == 21) if (Face_Down_Ten) { Dealer_Card_1.Image = Dealer_Down_Card.Get_Image(); Decision(false, false, false, true); return; } //string Possible_Values = ""; Dealer_Current_Total += 1; // 11 Dealer_Result_TextBox.Text = "1/11"; // dealer still has a face down. Dealer_Hand_Count++; Player_Turn = true; } else { Dealer_Current_Total += c.Get_Integer_Value(); Dealer_Result_TextBox.Text = Dealer_Current_Total.ToString(); Dealer_Hand_Count++; Player_Turn = true; } } //textBox2.Text = d.Display_Discard_Pile_ToString(); //textBox1.Text = d.Display_Deck_ToString(); } else { textBox2.Text = "Empty deck."; return; } //Remaining_Cards_Count_TextBox.Text = d.Get_Remaining_Cards().ToString(); Deal_Value++; //Console.WriteLine("Deal_Value: " + Deal_Value); // delay await Task.Delay(DELAY_TASK_TIME); } //Console.WriteLine("251: Deal_Value: " + Deal_Value); New_Hand = false; // Keep buttons disabled during initial dealing if (Dealer_Hand_Count >= 2) { Hit_Button.Enabled = true; Stand_Button.Enabled = true; Deal_Button.Enabled = false; Double_Button.Enabled = true; // if (Double_Down(Player_First_Card, Player_Second_Card)) { Player_First_Card = Player_Second_Card = 0; Double_Button.PerformClick(); // Stand to end player turn after double Stand_Button.PerformClick(); //return; // not tested // reset bet from doubling //Current_Bet /= 2; } Player_First_Card = Player_Second_Card = 0; } //Console.WriteLine("Decision Reached: " + Decision_Reached.ToString()); // make decision if player_decision_Textbox is empty (no decision) // reasons that it would not be empty are in player blackjack or outright WIN/LOSS // changed from if to while to allow multiple hits by player //while (Player_Decision_TextBox.Text.Equals("") && Deal_Value > 3) // added second condition 11:23 am 10/17 while ((!Decision_Reached) && Player_Decision_TextBox.Text.Equals("")) { // why is playeR_current_Total = if Deal_Value is 4???? //Console.WriteLine("INSIDE DEAL FUNCTION"); // if no aces, pass int values if (!Player_Result_TextBox.Text.Contains('/') && (!Dealer_Result_TextBox.Text.Contains('/'))) { // if the decision is NOT empty, a winner has been decided. //Console.WriteLine("This portion should only be executed at the end of a hand."); //Console.WriteLine("Deal_Value: " + Deal_Value); Console.WriteLine("314: Player_Result_TextBox: " + Player_Result_TextBox.Text + " Dealer_Result_TextBox: " + Dealer_Result_TextBox.Text); Decide(Convert.ToInt32(Player_Result_TextBox.Text), Convert.ToInt32(Dealer_Result_TextBox.Text)); } // if there are aces, else { Decide(Player_Result_TextBox.Text, Dealer_Result_TextBox.Text); } // update Player_Decision_TextBox value to exit loop // Maybe update player deciion textbox inside Decide(); } //Decision_Reached = false; // tried to click clear here, doesn't work // delay before dealing next hand /*if (!d.Is_Empty()) * { * * await Task.Delay(DELAY_TASK_TIME); * Deal_Button.PerformClick(); * } * else * { * Display_Empty_Message(); * }*/ }
private void Hit_Button_Click(object sender, EventArgs e) { Player_Turn = true; if (!d.Is_Empty()) { Card c = d.Draw(); //update textbox Remaining_Cards_Count_TextBox.Text = d.Get_Remaining_Cards().ToString(); if (Player_Hand_Count == 2) { Player_Card_3.Image = c.Get_Image(); } else if (Player_Hand_Count == 3) { Player_Card_4.Image = c.Get_Image(); } else if (Player_Hand_Count == 4) { Player_Card_5.Image = c.Get_Image(); } else if (Player_Hand_Count == 5) { Player_Card_6.Image = c.Get_Image(); } else if (Player_Hand_Count == 6) { Player_Card_7.Image = c.Get_Image(); } // Check for ace if (Player_Result_TextBox.Text.Contains('/')) { // check for 21 if (Player_Current_Total + 11 == 21) { Player_Current_Total = 21; Player_Result_TextBox.Text = "21"; Stand_Button.PerformClick(); } //no 21 - perform calculation with ace in hand else { int Possible_Value_1 = Player_Current_Total + c.Get_Integer_Value(); int Possible_Value_2 = Possible_Value_1 + 10; Player_Current_Total = Possible_Value_1; Player_Result_TextBox.Text = Possible_Value_1.ToString() + "/" + Possible_Value_2.ToString(); Player_Hand_Count++; // end hand if player busts and reveal dealer card if (Player_Current_Total > 21) { Dealer_Card_1.Image = Dealer_Down_Card.Get_Image(); // Dealer results not calculated since player busted Decision(true, false, false, false); return; } } } else { Player_Current_Total += c.Get_Integer_Value(); Player_Result_TextBox.Text = Player_Current_Total.ToString(); Player_Hand_Count++; // end hand if player busts and reveal dealer card if (Player_Current_Total > 21) { Dealer_Card_1.Image = Dealer_Down_Card.Get_Image(); // Dealer results not calculated since player busted Decision(true, false, false, false); return; } } } // else deck is empty else { Display_Empty_Message(); return; } }