Esempio n. 1
0
        public void Start()
        {
            while (true)
            {
                int originalBet = OnRoundBet(new OnRoundBetArgs()
                {
                    Player = _player
                });
                int handBet      = originalBet;
                int splitHandBet = originalBet;
                _player.Account = _player.Account - originalBet;

                Round round = new Round(_player, _deck);

                round.OnRoundStart += (ev) =>
                {
                    OnRoundStart(ev);
                };

                round.OnRoundInsurance += (ev) =>
                {
                    return(OnRoundInsurance(ev));
                };

                round.OnRoundIfInsurance += (ev) =>
                {
                    OnRoundIfInsurance?.Invoke(ev);
                };

                round.OnRoundDouble += (ev) =>
                {
                    if (originalBet < _player.Account)
                    {
                        return(OnRoundDouble(ev));
                    }
                    else
                    {
                        return(DoubleAction.No);
                    }
                };

                round.OnRoundIfDouble += (ev) =>
                {
                    _player.Account = _player.Account - originalBet;

                    if (ev.Hand.IsSplit)
                    {
                        splitHandBet = splitHandBet * 2;
                    }
                    else
                    {
                        handBet = originalBet * 2;
                    }

                    OnRoundIfDouble?.Invoke(ev);
                };

                round.OnRoundSplit += (ev) =>
                {
                    if (originalBet < _player.Account)
                    {
                        return(OnRoundSplit(ev));
                    }
                    else
                    {
                        return(SplitAction.No);
                    }
                };

                round.OnRoundIfSplit += (ev) =>
                {
                    _player.Account = _player.Account - originalBet;
                    OnRoundIfSplit?.Invoke(ev);
                };

                round.OnRoundTurnDecision += (ev) =>
                {
                    return(OnRoundTurnDecision(ev));
                };

                round.OnRoundTurnStart += (ev) =>
                {
                    OnRoundTurnStart(ev);
                };

                round.OnRoundDeal += (ev) =>
                {
                    OnRoundDeal(ev);
                };

                round.OnRoundStay += (ev) =>
                {
                    OnRoundStay(ev);
                };

                round.OnRoundBust += (ev) =>
                {
                    OnRoundBust(ev);
                };

                round.OnRoundHoleCardReveal += (ev) =>
                {
                    OnRoundHoleCardReveal(ev);
                };

                round.OnRoundHandResult += (ev) =>
                {
                    int bet = 0;
                    if (ev.Hand.IsSplit)
                    {
                        bet = splitHandBet;
                    }
                    else
                    {
                        bet = handBet;
                    }

                    if (ev.Result == HandResult.BlackJack)
                    {
                        _player.Account = _player.Account + (int)(bet * 2.5);
                    }
                    else if (ev.Result == HandResult.Tie)
                    {
                        _player.Account = _player.Account + bet;
                    }
                    else if (ev.Result == HandResult.Win)
                    {
                        _player.Account = _player.Account + bet * 2;
                    }
                    else if (ev.Result == HandResult.InsuranceBlackJack)
                    {
                        _player.Account = bet / 2 + _player.Account;
                    }

                    OnRoundHandResult(ev);
                };

                round.Start();

                RoundEndAction roundEndAction = OnRoundEnd(new OnRoundEndArgs());

                if (roundEndAction == RoundEndAction.Quit)
                {
                    break;
                }
            }
        }