コード例 #1
0
        public void AddCardTest()
        {
            BlackJackHand hand = new BlackJackHand(false);

            hand.AddCard(new Card(Card.CardSuites.Diamond, Card.CardRanks.Ace));
            Assert.AreEqual(hand.HandStatus, BlackJackHand.HandStatusTypes.None);
            Assert.AreEqual(hand.HandValue, 11);

            hand.AddCard(new Card(Card.CardSuites.Diamond, Card.CardRanks.Ace));
            Assert.AreEqual(hand.HandStatus, BlackJackHand.HandStatusTypes.None);
            Assert.AreEqual(hand.HandValue, 12);
            Assert.IsTrue(hand.IsSplittingAllowed);

            hand.AddCard(new Card(Card.CardSuites.Club, Card.CardRanks.Eight));
            Assert.AreEqual(hand.HandStatus, BlackJackHand.HandStatusTypes.None);
            Assert.AreEqual(hand.HandValue, 20);

            hand.AddCard(new Card(Card.CardSuites.Club, Card.CardRanks.Eight));
            Assert.AreEqual(hand.HandStatus, BlackJackHand.HandStatusTypes.None);
            Assert.AreEqual(hand.HandValue, 18);

            hand.AddCard(new Card(Card.CardSuites.Spade, Card.CardRanks.Queen));
            Assert.AreEqual(hand.HandStatus, BlackJackHand.HandStatusTypes.Busted);
            Assert.AreEqual(hand.HandValue, 28);

            try
            {
                hand.AddCard(new Card(Card.CardSuites.Heart, Card.CardRanks.Six));
                Assert.Fail("Should have occured InvalidGameOperationException");
            }
            catch (InvalidGameActionException igaEx)
            {
            }
        }
コード例 #2
0
        public void SplitHandTest()
        {
            BlackJackHand hand = new BlackJackHand(false);
            hand.AddCard(new Card(Card.CardSuites.Diamond, Card.CardRanks.Jack));
            hand.AddCard(new Card(Card.CardSuites.Diamond, Card.CardRanks.Queen));
            Assert.IsTrue(hand.IsSplittingAllowed);

            BlackJackHand handSplitted = hand.SplitHand();
            Assert.IsNotNull(handSplitted);
            Assert.AreNotSame(handSplitted, hand);

            Assert.IsFalse(hand.IsSplittingAllowed);
            Assert.IsFalse(handSplitted.IsSplittingAllowed);

            try
            {
                hand.SplitHand();
                Assert.Fail("Should have thrown InvalidGameException as hand is already splitted.");
            }
            catch (InvalidGameActionException igaEx)
            {
            }
        }
コード例 #3
0
        /// <summary>
        /// Split hand.
        /// </summary>
        /// <returns>Newly created hand after splitting.</returns>
        /// <exception cref="InvalidGameException">Thrown when hand is not in state when it's allowed to split. Check IsSplitAllowed property to check whether splitting is allowed or not.</exception>
        public BlackJackHand SplitHand()
        {
            if (IsSplittingAllowed)
            {
                BlackJackHand splittedHand = new BlackJackHand(true);
                splittedHand.AddCard(lstCards[1]);
                this.lstCards.Remove(lstCards[1]);
                this.IsSplittingAllowed = false;
                this.isSplittedHand = true;
                ReCalculateHandValue();

                return splittedHand;
            }
            else
            {
                throw new Exceptions.InvalidGameActionException("Hand can not be splitted in current state. Check IsSplitAllowed property to check whether splitting is allowed or not.");
            }
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: rumitparakhiya/BlackJack
 /// <summary>
 /// Requests a new card from dealer and adds it to hand.
 /// </summary>
 /// <param name="hand">Hand to add card in.</param>
 private void PullCard(BlackJackHand hand)
 {
     hand.AddCard(dealer.DealCard());
 }
コード例 #5
0
ファイル: Player.cs プロジェクト: rumitparakhiya/BlackJack
 /// <summary>
 /// Method to take hit action.
 /// </summary>
 /// <param name="hand">Hand on which hit is requested.</param>
 /// <exception cref="InvalidGameActionException">Thrown when hand is busted and player tries to add more cards to it.</exception>
 public void Hit(BlackJackHand hand)
 {
     hand.AddCard(dealer.DealCard());
 }