Ejemplo n.º 1
0
        /// <summary>
        ///     Splits the hand.
        /// </summary>
        /// <param name="shoe">The shoe.</param>
        /// <param name="player">The player.</param>
        /// <returns></returns>
        public bool SplitHand(BjShoe shoe, BjPlayer player)
        {
            if (Cards.Count != 2)
            {
                return(false);
            }

            BjHand hand  = null;
            var    card1 = Cards[0];
            var    card2 = Cards[1];

            if (card1 != null && card2 != null &&
                card1.Face == card2.Face)
            {
                hand = new BjHand(Bet, card2);
            }

            if (hand == null)
            {
                return(false);
            }

            if (!Cards.Remove(hand.Cards.FirstOrDefault()) || !HitHand(shoe) || !hand.HitHand(shoe))
            {
                return(false);
            }

            player.CurrentHands.Add(hand);
            return(true);
        }
        /// <summary>
        ///     Draws the active hand.
        /// </summary>
        /// <param name="hand">The hand.</param>
        /// <param name="xStartPos">The x start position.</param>
        /// <param name="yPos">The y position.</param>
        /// <param name="width">The width.</param>
        public static async void DrawActiveHand(this BjHand hand, float xStartPos, float yPos, float width)
        {
            if (hand?.Cards == null)
            {
                return;
            }
            await LoadCardTextures();

            BjDraw.DrawActiveHandBackground(width, xStartPos + width * 2.2f, yPos);

            float offSet = 0f;

            for (int index = 0; index < hand.Cards.Count; index++)
            {
                float offsetMultiplier = 1.1f;
                if (hand.Cards.Count > 5 && index < hand.Cards.Count - 1)
                {
                    offsetMultiplier = 0.2f;
                }

                float offsetDelta = width * offsetMultiplier;
                offSet = offSet + offsetDelta;

                if (index == 0)
                {
                    offSet = 0f;
                }

                BjDraw.DrawCard(hand.Cards[index], xStartPos + offSet, yPos, width);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Determines whether [is split success] [the specified hand].
 /// </summary>
 /// <param name="hand">The hand.</param>
 /// <param name="shoe">The shoe.</param>
 /// <returns>
 ///     <c>true</c> if [is split success] [the specified hand]; otherwise, <c>false</c>.
 /// </returns>
 public bool IsSplitSuccess(BjHand hand, BjShoe shoe)
 {
     if (!HandExists(hand))
     {
         return(false);
     }
     return(hand.SplitHand(shoe, this));
 }
Ejemplo n.º 4
0
 /// <summary>
 ///     Determines whether [is double down success] [the specified hand].
 /// </summary>
 /// <param name="hand">The hand.</param>
 /// <param name="shoe">The shoe.</param>
 /// <returns>
 ///     <c>true</c> if [is double down success] [the specified hand]; otherwise, <c>false</c>.
 /// </returns>
 public bool IsDoubleDownSuccess(BjHand hand, BjShoe shoe)
 {
     if (!HandExists(hand))
     {
         return(false);
     }
     return(hand.HitHand(shoe));
 }
Ejemplo n.º 5
0
 public void DebugHands(int numberOfhands)
 {
     for (int i = 0; i < numberOfhands; i++)
     {
         var hand   = new BjHand(10);
         int number = Rand.GetRange(2, 8);
         hand.DebugSetHand(number);
         CurrentHands.Add(hand);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        ///     Hands the exists.
        /// </summary>
        /// <param name="hand">The hand.</param>
        /// <returns></returns>
        private bool HandExists(BjHand hand)
        {
            if (!CurrentHands.Contains(hand))
            {
                Log.Error("CheckHand: hand missing from CurrentHands.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Deals the new round.
        /// </summary>
        /// <param name="shoe">The shoe.</param>
        /// <returns></returns>
        public bool DealNewRound(BjShoe shoe)
        {
            var hand = new BjHand(CurrentBet);

            if (!hand.HitHand(shoe))
            {
                return(false);
            }

            CurrentHands = new List <BjHand> {
                hand
            };
            return(true);
        }
        /// <summary>
        ///     Draws the initial dealer hand.
        /// </summary>
        /// <param name="hand">The hand.</param>
        /// <param name="screenX">The screen x.</param>
        /// <param name="screenY">The screen y.</param>
        /// <param name="width">The width.</param>
        public static async void DrawInitialDealerHand(this BjHand hand, float screenX, float screenY, float width)
        {
            if (hand?.Cards == null)
            {
                return;
            }
            await LoadCardTextures();

            const float heightMultiplier = 2.5f;
            string      dict             = "standard_cards";

            BjDraw.DrawDealerBackground(width);
            API.DrawSprite(dict, "back", screenX, screenY, width,
                           width * heightMultiplier, 0,
                           255, 255, 255, 255);

            BjDraw.DrawCard(hand.Cards[1], screenX + width * 1.1f, screenY, width);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Deals the round starting cards.
        /// </summary>
        /// <param name="shoe">The shoe.</param>
        /// <param name="players">The players.</param>
        /// <returns></returns>
        public bool DealRoundStartingCards(BjShoe shoe, List <BjPlayer> players)
        {
            var allPlayersDealt = true;

            CurrentHand = new BjHand();
            for (int i = 0; i < 2; i++)
            {
                foreach (var player in players)
                {
                    if (player.CurrentBet <= 0 || player.CurrentBet > player.Chips || player.CurrentBet < Blackjack.CurrentGame.MinimumBet)
                    {
                        Log.Info($"DealRoundStartingCards: bet={player.CurrentBet},chips={player.Chips},minBet={Blackjack.CurrentGame.MinimumBet}");
                        allPlayersDealt = false;
                        continue;
                    }
                    if (i == 0)
                    {
                        if (!player.DealNewRound(shoe))
                        {
                            Log.Info($"Failed to deal player new round.");
                            return(false);
                        }
                    }
                    else
                    {
                        var hand = player.CurrentHands.FirstOrDefault();
                        if (!player.IsHitSuccess(hand, shoe))
                        {
                            Log.Info($"Failed to deal player 2nd card.");
                            return(false);
                        }
                    }
                }

                if (!CurrentHand.HitHand(shoe))
                {
                    Log.Info($"Failed to hit dealer.");
                    return(false);
                }
            }

            return(allPlayersDealt);
        }
Ejemplo n.º 10
0
 public BjDealer(int netId, string name)
 {
     NetId       = netId;
     Name        = name;
     CurrentHand = new BjHand();
 }