Пример #1
0
        /// <summary>
        /// Initialize a new game.
        /// Create a 6 deck pack and shuffle it.
        /// Draw 2 cards to both the dealer and the player.
        /// </summary>
        /// <param name="randomGenerator"></param>
        public Game(Random randomGenerator)
        {
            this.Deck = new CardPack(6);
            for (int shuffles = 0; shuffles < 20; shuffles++)
            {
                this.Deck.Shuffle(randomGenerator);
            }

            this.DealerBot = new Dealer();
            this.PlayerBot = new Player();

            for (int initialDraw = 0; initialDraw < 2; initialDraw++)
            {
                this.DealerBot.DealerHand.AddCard(this.Deck.DrawCard());
                this.PlayerBot.PlayerHand.AddCard(this.Deck.DrawCard());
            }
        }
Пример #2
0
        /// <summary>
        /// Predetermined actions the dealer must take when the player is done.
        /// </summary>
        /// <param name="pack"></param>
        public void Play(CardPack pack)
        {
            //draw card until reaching 17 or over.
            while (this.DealerHand.Value < 17)
            {
                this.DealerHand.AddCard(pack.DrawCard());
            }
            //hit if at soft 17, soften hand if hand is soft and over blackjack (21).
            if (this.DealerHand.IsSoft == true)
            {
                if (this.DealerHand.Value == 17)
                {
                    this.DealerHand.AddCard(pack.DrawCard());
                }
                if (this.DealerHand.Value > 21)
                {
                    this.DealerHand.SoftenValue();
                }
            }

            //reveal true hand value in order to determine game result.
            this.DealerHand.DealerEndGameValue();
        }
Пример #3
0
 /// <summary>
 /// HIT! action - draw a card and add it to the player hand.
 /// When the player chooses to DOUBLE!, he hit.
 /// </summary>
 /// <param name="pack"></param>
 public void Hit(CardPack pack)
 {
     this.PlayerHand.AddCard(pack.DrawCard());
 }