Exemplo 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();
 }
Exemplo n.º 2
0
 public SplitHandHandler(IUnitOfWorkFactory unit_of_work_factory,
                         IRepository <BlackJackTable> blackjack_table_repository,
                         SplitHand dealer)
 {
     _unit_of_work_factory       = unit_of_work_factory;
     this._dealer                = dealer;
     _blackjack_table_repository = blackjack_table_repository;
 }
Exemplo n.º 3
0
 private void _on_BtnSplit_pressed()
 {
     if (GameState.CurrentHero.Gold >= (MainBet * 2))
     {
         AddTextToTextBox("You split your hand.");
         SplitBet = MainBet;
         Card moveCard = new Card(MainHand.CardList[1]);
         MainHand.CardList.RemoveAt(1);
         mainHandContainer.GetChild(1).Free();
         SplitHand.AddCard(moveCard);
         BtnSplit.Disabled          = true;
         splitHandContainer.Visible = true;
         SplitHandOver = false;
         DealCard(MainHand);
         DealCard(SplitHand);
         CheckWinConditions();
     }
     else
     {
         AddTextToTextBox("You cannot afford to double your wager to split your hands.");
     }
 }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
 /// <summary>Toggles the Split Hand's Hit and Stay Buttons' Disabled property.</summary>
 /// <param name="disabled">Should the Buttons be disabled?</param>
 private void ToggleSplitHandButtons(bool disabled)
 {
     BtnHitSplit.Disabled        = disabled;
     BtnStaySplit.Disabled       = disabled;
     BtnDoubleDownSplit.Disabled = !SplitHand.CanDoubleDown();
 }