Example #1
0
        public void Payout(BlackjackPlayer player)
        {
            BlackjackHand dealerHand = this.Hand;
            BlackjackHand playerHand = this.Hand;
            decimal       winnings   = 0;

            if (playerHand.Busted)
            {
                winnings = 0;
            }
            else if (playerHand.Blackjack)
            {
                winnings = playerHand.Bet * 2.5m;
            }
            else if (dealerHand.GetValue() == playerHand.GetValue())
            {
                winnings = playerHand.Bet;
            }
            else if (dealerHand.Busted || dealerHand.GetValue() < playerHand.GetValue())
            {
                winnings = playerHand.Bet * 2m;
            }

            player.User.Bankroll += winnings;
        }
Example #2
0
        public void Bet(decimal amount)
        {
            if (this.Game == null)
            {
                throw new Exception("Player cannot bet if they are not part of a game.");
            }
            if (this.User.Bankroll < amount)
            {
                throw new Exception("Player cannot bet more than they have.");
            }

            // take bet amount from players bankroll.
            this.User.Bankroll -= amount;

            // deal hand to player
            BlackjackHand hand = new BlackjackHand(amount);

            Card firstCard = this.Game.Dealer.Deal();

            hand.Hit(firstCard);

            Card secondCard = this.Game.Dealer.Deal();

            hand.Hit(secondCard);

            // assign that hand to the player.
            this.Hand = hand;
        }
Example #3
0
        public bool ShouldStandWith(BlackjackHand hand)
        {
            bool should = false;

            if (hand.GetValue() >= 16)
            {
                should = true;
            }

            return(should);
        }
Example #4
0
 public BlackjackDealer(int deck_count = 6)
 {
     try
     {
         this.Deck = new Deck(deck_count);
         this.Deck.Shuffle();
         BlackjackHand newHand   = new BlackjackHand(0);
         Card          shownCard = this.Deal();
         newHand.Hit(shownCard);
         Card hiddenCard = this.Deal(true);
         newHand.Hit(hiddenCard);
         this.Hand = newHand;
     }
     catch (Exception ex)
     {
         throw new Exception("Could not create dealer: " + ex);
     }
 }