Exemplo n.º 1
0
        public void HandleRequestToHit(BlackjackGamePlayer player)
        {
            if (RoundInProgress == null)
            {
                throw new InvalidOperationException("No round in play");
            }

            var roundplayer = RoundInProgress.GetRoundPlayer(player);

            if (roundplayer == null)
            {
                throw new ArgumentException("'player' is null or invalid");
            }

            if (!roundplayer.HasAction || roundplayer.Hand == null)
            {
                throw new InvalidOperationException("Out of turn");
            }

            if (roundplayer.Hand.IsBusted)
            {
                throw new InvalidOperationException("Cannot hit busted hand");
            }

            roundplayer.AddCardToHand(_shoe.DealCard());

            if (roundplayer.Hand.IsBusted)
            {
                moveToNextAction();
            }
        }
Exemplo n.º 2
0
        public void HandleRequestToDoubleDown(BlackjackGamePlayer player, double amount)
        {
            if (RoundInProgress == null)
            {
                throw new InvalidOperationException("No round in play");
            }

            var roundplayer = RoundInProgress.GetRoundPlayer(player);

            if (roundplayer == null)
            {
                throw new ArgumentException("'player' is null or invalid");
            }

            if (!roundplayer.HasAction || roundplayer.Hand == null)
            {
                throw new InvalidOperationException("Out of turn");
            }

            if (roundplayer.Hand.Cards.Count() != 2)
            {
                throw new InvalidOperationException("Must have 2 cards to double");
            }

            if (amount > roundplayer.Wager)
            {
                throw new InvalidOperationException("Amounts exceeds current wager");
            }

            roundplayer.AddCardToHand(_shoe.DealCard());
            roundplayer.Wager += amount;
            roundplayer.Player.Account.Debit(amount);

            moveToNextAction();
        }
Exemplo n.º 3
0
        internal void PlaceWager(BlackjackGamePlayer player, double amount)
        {
            if (!_players.Contains(player))
            {
                throw new InvalidOperationException("'player' is null or invalid");
            }

            if (player.IsLive)
            {
                throw new InvalidOperationException("Player is in live round");
            }

            if (_roundPlayersQueuedForNextRound.Any(a => a.Player.Id == player.Id))
            {
                throw new InvalidOperationException();
            }

            if (amount > player.Account.Balance)
            {
                throw new InvalidOperationException("Insufficient funds");
            }

            if (amount < MinWager || amount > MaxWager)
            {
                throw new InvalidOperationException("Player wager is out of range");
            }

            player.Account.Debit(amount);
            _roundPlayersQueuedForNextRound.Add(new BlackjackGameRoundPlayer(player, amount));
        }
Exemplo n.º 4
0
        internal void RequestToDoubleDown(BlackjackGamePlayer player, double amount)
        {
            if (amount > player?.Account?.Balance)
            {
                throw new InvalidOperationException("Insufficient funds");
            }

            _dealer.HandleRequestToDoubleDown(player, amount);
        }
Exemplo n.º 5
0
        public BlackjackHandSettlement SettleHand(BlackjackGamePlayer player)
        {
            var roundplayer = RoundInProgress.GetRoundPlayer(player);

            if (roundplayer == null)
            {
                throw new ArgumentException("'player' is null or invalid");
            }

            return(settleHand(roundplayer));
        }
Exemplo n.º 6
0
        public void RemovePlayer(BlackjackGamePlayer player)
        {
            if (_players.Contains(player))
            {
                if (player.IsLive)
                {
                    throw new InvalidOperationException("Player is in live round");
                }

                _players.Remove(player);
                _roundPlayersQueuedForNextRound
                .Remove(_roundPlayersQueuedForNextRound
                        .FirstOrDefault(a => a.Player.Id == player.Id));
            }
        }
        public BlackjackGameRoundPlayer(BlackjackGamePlayer player, double wager)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player", "Player is null");
            }

            if (wager <= 0)
            {
                throw new InvalidOperationException("Wager cannot be negative");
            }

            _cards = new List <Card>();
            Player = player;
            Wager  = wager;
        }
Exemplo n.º 8
0
        public void HandleRequestToStand(BlackjackGamePlayer player)
        {
            if (RoundInProgress == null)
            {
                throw new InvalidOperationException("No round in play");
            }

            var roundplayer = RoundInProgress.GetRoundPlayer(player);

            if (roundplayer == null)
            {
                throw new ArgumentException("'player' is null or invalid");
            }

            if (!roundplayer.HasAction || roundplayer.Hand == null)
            {
                throw new InvalidOperationException("Out of turn");
            }

            moveToNextAction();
        }
Exemplo n.º 9
0
 internal bool GetPlayerHasAction(BlackjackGamePlayer player)
 {
     return(_roundInProgress?.GetRoundPlayer(player)?.HasAction ?? false);
 }
Exemplo n.º 10
0
 internal double GetPlayerWager(BlackjackGamePlayer player)
 {
     return(_roundInProgress?.GetRoundPlayer(player)?.Wager
            ?? _roundPlayersQueuedForNextRound.SingleOrDefault(a => a.Player.Id == player.Id)?.Wager
            ?? 0);
 }
Exemplo n.º 11
0
 internal BlackjackHand GetPlayerHand(BlackjackGamePlayer player)
 {
     return(_roundInProgress?.GetRoundPlayer(player)?.Hand);
 }
Exemplo n.º 12
0
 internal bool GetPlayerIsLive(BlackjackGamePlayer player)
 {
     return(_roundInProgress?.GetRoundPlayer(player) != null);
 }
Exemplo n.º 13
0
 internal void RequestToStand(BlackjackGamePlayer player)
 {
     _dealer.HandleRequestToStand(player);
 }
Exemplo n.º 14
0
 public BlackjackHandSettlement SettlePlayerHand(BlackjackGamePlayer player)
 {
     return(_dealer.SettleHand(player));
 }
Exemplo n.º 15
0
 public BlackjackGameRoundPlayer GetRoundPlayer(BlackjackGamePlayer player)
 {
     return(_roundPlayers.SingleOrDefault(a => a.Player.Id == player.Id));
 }