コード例 #1
0
        public virtual void StartRound()
        {
            RoundClosedBecauseOfDealer21 = false;
            if (IsRoundInProgress)
            {
                throw new InvalidOperationException("Live round in progress");
            }

            if (!RoundPlayersQueuedForNextRound.Any())
            {
                throw new InvalidOperationException("No players have wagered");
            }

            var roundInProgress = new BlackjackGameRound(RoundPlayersQueuedForNextRound);

            RoundPlayersQueuedForNextRound.Clear();

            Dealer.Deal(roundInProgress);

            if (DealerHas21)
            {
                EndRound();
                RoundClosedBecauseOfDealer21 = true;
            }
        }
コード例 #2
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));
        }
コード例 #3
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));
            }
        }
コード例 #4
0
 internal double GetPlayerWager(BlackjackGamePlayer player)
 {
     return(_roundInProgress?.GetRoundPlayer(player)?.Wager
            ?? RoundPlayersQueuedForNextRound.SingleOrDefault(a => a.Player.Id == player.Id)?.Wager
            ?? 0);
 }