Esempio n. 1
0
 /// <summary>Checks which Buttons should be enabled.</summary>
 private void CheckButtons()
 {
     ToggleMainHandButtons(MainHand.ActualValue >= 21 || MainHandOver);
     BtnConvertAce.Disabled = !MainHand.HasAceEleven();
     ToggleSplitHandButtons(SplitHand.ActualValue >= 21 || SplitHandOver);
     BtnConvertAceSplit.Disabled = !SplitHand.HasAceEleven();
 }
Esempio n. 2
0
        /// <summary>Determines whether the round is over.</summary>
        private void CheckWinConditions()
        {
            if (MainHandOver && SplitHandOver)
            {
                ToggleMainHandButtons(true);
                ToggleSplitHandButtons(true);
                ToggleInsurance(true);
                // check whether or not the dealer needs to take any action
                // I do not recognize the dealer winning with Five Card Charlie, as it's a house rule, anyway. Only the player can win with it.
                // when I try to merge or invert these if statements, it doesn't work right. VS must not have the right operator precendence.
                if (MainHand.HasBlackjack() && SplitHand.HasBlackjack())
                {
                }
                else if (MainHand.IsBust() && SplitHand.IsBust())
                {
                }
                else if (SplitHand.Count == 0 && (MainHand.HasBlackjack() || MainHand.IsBust() || MainHand.HasFiveCardCharlie()))
                {
                }
                else if ((MainHand.HasBlackjack() && SplitHand.IsBust()) || (MainHand.IsBust() && SplitHand.HasBlackjack()))
                {
                }
                else if (MainHand.HasFiveCardCharlie() && (SplitHand.IsBust() || SplitHand.HasBlackjack()))
                {
                }
                else
                {
                    DealerAction();
                }
                DisplayDealerHand();

                if (MainHand.IsBust())
                {
                    AddTextToTextBox("Your main hand busts!" + LoseBlackjack(MainBet));
                }
                else if (MainHand.HasBlackjack() && MainHand.Count == 2)
                {
                    if (DealerHand.ActualValue != 21)
                    {
                        AddTextToTextBox("Your main hand is a natural blackjack!" + WinBlackjack(Int32Helper.Parse(MainBet * 1.5)));
                    }
                    else
                    {
                        AddTextToTextBox("Your main hand and the dealer both have natural blackjacks." + DrawBlackjack());
                    }
                }
                else if (DealerHand.IsBust())
                {
                    AddTextToTextBox("Dealer busts!" + WinBlackjack(MainBet));
                }
                else if (MainHand.HasBlackjack() && (DealerHand.IsBust() || DealerHand.ActualValue < 21))
                {
                    AddTextToTextBox("Your main hand is 21!" + WinBlackjack(MainBet));
                }
                else if (MainHand.HasFiveCardCharlie())
                {
                    if (!DealerHand.HasBlackjack())
                    {
                        AddTextToTextBox("Your main hand is a Five Card Charlie!" + WinBlackjack(MainBet));
                    }
                    else
                    {
                        AddTextToTextBox("Your main hand is a Five Card Charlie, but the dealer had a natural blackjack." + DrawBlackjack());
                    }
                }
                else if (MainHand.ActualValue > DealerHand.ActualValue && !DealerHand.IsBust())
                {
                    AddTextToTextBox("Your main hand's cards are worth more than the dealer's!" + WinBlackjack(MainBet));
                }
                else if (MainHand.ActualValue == DealerHand.ActualValue)
                {
                    AddTextToTextBox("Your main hand's cards are worth the same as the dealer's." + DrawBlackjack());
                }
                else if (MainHand.ActualValue < DealerHand.ActualValue)
                {
                    AddTextToTextBox("Your main hand's cards are worth less than the dealer's." + LoseBlackjack(MainBet));
                }

                //check split hand
                if (SplitHand.Count != 0)
                {
                    if (SplitHand.IsBust())
                    {
                        AddTextToTextBox("Your split hand busts!" + LoseBlackjack(SplitBet));
                    }
                    else if (SplitHand.HasBlackjack() && SplitHand.Count == 2)
                    {
                        if (DealerHand.ActualValue != 21)
                        {
                            AddTextToTextBox("Your split hand is a natural blackjack!" + WinBlackjack(Int32Helper.Parse(SplitBet * 1.5)));
                        }
                        else
                        {
                            AddTextToTextBox("Your split hand and the dealer both have natural blackjacks." + DrawBlackjack());
                        }
                    }
                    else if (DealerHand.IsBust())
                    {
                        AddTextToTextBox("Dealer busts!" + WinBlackjack(SplitBet));
                    }
                    else if (SplitHand.HasBlackjack() && (DealerHand.IsBust() || DealerHand.ActualValue < 21))
                    {
                        AddTextToTextBox("Your split hand is 21!" + WinBlackjack(SplitBet));
                    }
                    else if (SplitHand.HasFiveCardCharlie())
                    {
                        if (!DealerHand.HasBlackjack())
                        {
                            AddTextToTextBox("Your split hand is a Five Card Charlie!" + WinBlackjack(SplitBet));
                        }
                        else
                        {
                            AddTextToTextBox("Your split hand is a Five Card Charlie, but the dealer had a natural blackjack." + DrawBlackjack());
                        }
                    }
                    else if (SplitHand.ActualValue > DealerHand.ActualValue && !DealerHand.IsBust())
                    {
                        AddTextToTextBox("Your split hand's cards are worth more than the dealer's!" + WinBlackjack(SplitBet));
                    }
                    else if (SplitHand.ActualValue == DealerHand.ActualValue)
                    {
                        AddTextToTextBox("Your split hand's cards are worth the same as the dealer's." + DrawBlackjack());
                    }
                    else if (SplitHand.ActualValue < DealerHand.ActualValue)
                    {
                        AddTextToTextBox("Your split hand's cards are worth less than the dealer's." + LoseBlackjack(SplitBet));
                    }
                }

                //check side pot
                if (SidePot > 0 && DealerHand.Count == 2 && DealerHand.HasBlackjack())
                {
                    AddTextToTextBox("Your insurance paid off!" + WinBlackjack(SidePot));
                }
                else if (SidePot > 0)
                {
                    AddTextToTextBox("Your insurance didn't pay off." + LoseBlackjack(SidePot));
                }
            }
            else if (!MainHandOver)
            {
                if (MainHand.HasBlackjack() || MainHand.IsBust() || (MainHand.Count == 5 && (MainHand.ActualValue < 21 || (MainHand.HasAceEleven() && MainHand.ActualValue <= 31))))
                {
                    MainHandOver = true;
                    CheckWinConditions();
                }
                else
                {
                    CheckButtons();
                }
            }
            else if (!SplitHandOver)
            {
                if (SplitHand.HasBlackjack() || SplitHand.IsBust() || (SplitHand.Count == 5 && (SplitHand.ActualValue < 21 || (SplitHand.HasAceEleven() && SplitHand.ActualValue <= 31))))
                {
                    SplitHandOver = true;
                    CheckWinConditions();
                }
                else
                {
                    CheckButtons();
                }
            }

            DisplayHands();
        }