Exemple #1
0
        public void TestPlayerHandCardsConstructor()
        {
            PlayerHandCards playerHandCards = new PlayerHandCards(12);

            Assert.AreEqual(12, playerHandCards.BetAmount);
            Assert.IsFalse(playerHandCards.HasSurrendered);
        }
Exemple #2
0
        public void TestSplitCards()
        {
            PlayerHandCards playerHandCards = new PlayerHandCards(10);
            GameContext     gameContext     = new GameContext();

            playerHandCards.AddCard(7);
            playerHandCards.AddCard(7);
            Assert.IsTrue(playerHandCards.EligibleToSplit(1, gameContext));
            playerHandCards.AddCard(7);
            Assert.IsFalse(playerHandCards.EligibleToSplit(1, gameContext)); // more than 2 cards

            playerHandCards = new PlayerHandCards(10);
            playerHandCards.AddCard(10);
            playerHandCards.AddCard(12);
            Assert.IsFalse(playerHandCards.EligibleToSplit(1, gameContext));
            Assert.IsNull(playerHandCards.SplitAndGetNewHandCards(3, 6, gameContext));

            gameContext.TreatAllTensEqual = true;
            Assert.IsTrue(playerHandCards.EligibleToSplit(1, gameContext)); // when all ten values are treated the same, it can be split
            HandCards newHand = playerHandCards.SplitAndGetNewHandCards(4, 8, gameContext);

            Assert.IsNotNull(newHand);
            Assert.AreEqual("J5", playerHandCards.ToString());
            Assert.AreEqual("K9", newHand.ToString());
        }
        public PlayerHandCards SplitAndGetNewHandCards(int val1, int val2, GameContext gameContext)
        {
            if (this.EligibleToSplit(1, gameContext))
            {
                PlayerHandCards newHand = new PlayerHandCards(this.BetAmount);
                newHand.AddCard(this.ReverseAdd());
                newHand.AddCard(val2);
                this.AddCard(val1);
                return(newHand);
            }

            return(null);
        }
Exemple #4
0
 public void AddOpenHandEvent(int playerId, HandCards dealerCards, PlayerHandCards playerCards)
 {
     this.GameEvents.Add(
         new GameEvent(
             this.GameEvents.Count + 1,
             GameEventType.HandOpened,
             string.Format(
                 OpenHandMessageTemplate,
                 "Player" + playerId,
                 dealerCards,
                 playerCards,
                 playerCards.BetAmount)));
 }
        /// <summary>
        /// Desteden kart çeker eğer elinde 5 kartan az varsa eline alır yoksa yok eder
        /// </summary>
        public void DrawCard()
        {
            if (!PlayerCardDeck.Any())
            {
                return;
            }

            var random      = new Random();
            var drawingCard = PlayerCardDeck[random.Next(0, PlayerCardDeck.Count)];

            PlayerCardDeck.Remove(drawingCard);
            if (PlayerHandCards.Count < 5)
            {
                PlayerHandCards.Add(drawingCard);
            }
        }
Exemple #6
0
        public void TestEligibleToDoubleOrSurrender()
        {
            PlayerHandCards playerHandCards = new PlayerHandCards(10);
            GameContext     gameContext     = new GameContext();

            playerHandCards.AddCard(3);
            playerHandCards.AddCard(8);
            Assert.IsTrue(playerHandCards.EligibleToDouble(gameContext));
            playerHandCards.AddCard(7);
            Assert.IsFalse(playerHandCards.EligibleToDouble(gameContext)); // more than 2 cards

            playerHandCards = new PlayerHandCards(10);
            playerHandCards.AddCard(10);
            playerHandCards.AddCard(12);
            Assert.IsTrue(playerHandCards.EligibleToSurrender(gameContext));
            playerHandCards.AddCard(2);
            Assert.IsFalse(playerHandCards.EligibleToSurrender(gameContext)); // more than 2 cards
        }
Exemple #7
0
 public void AddEventByPlayerAction(
     PlayerAction playerAction,
     int playerId,
     HandCards dealerCards,
     PlayerHandCards playerCards,
     GameContext gameContext)
 {
     this.GameEvents.Add(
         new GameEvent(
             this.GameEvents.Count + 1,
             GameEventType.PlayerAction,
             string.Format(
                 GenericActionMessageTemplate,
                 "Player" + playerId,
                 playerAction.ToString().ToLower(),
                 dealerCards,
                 playerCards,
                 playerCards.BetAmount)));
 }
Exemple #8
0
 public void AddCloseHandEvent(
     int playerId,
     HandCards dealerCards,
     PlayerHandCards playerCards,
     decimal winAmount,
     string overrideResult = null)
 {
     this.GameEvents.Add(
         new GameEvent(
             this.GameEvents.Count + 1,
             GameEventType.HandClosed,
             string.Format(
                 CloseHandMessageTemplate,
                 "Player" + playerId,
                 dealerCards,
                 playerCards,
                 string.IsNullOrEmpty(overrideResult) ? GetResultByAmount(winAmount) : overrideResult,
                 winAmount)));
 }