Exemple #1
0
 private void DisplayOptions(int box, CardHand playerHand, bool splited = false)
 {
     if (box < 10)
     {
         //Debug.WriteLine("playerHand card value is {0}", playerHand.TotalCardValue);
         DoubleOrSplitBeingSelect = box;
         buttonStay.Enabled       = !(playerHand.TotalCardValue < 12);
         buttonDouble.Enabled     = (playerHand.Doubleable());
         if (splited == false)
         {
             //buttonSplit.Enabled = (true);
             buttonSplit.Enabled = (playerHand.Splitable());
         }
         if (box > 4)
         {
             box -= 5;
         }
         groupBoxOptions.Location = playerMenuLocation[box];
         groupBoxOptions.Visible  = true;
     }
     else
     {
         groupBoxOptions.Visible = false;
     }
 }
Exemple #2
0
 public Dealer(Graphics drawing, ShuffleMachine machine)
 {
     this.drawing = drawing;
     this.machine = machine;
     machine.Start();
     for (int i = 0; i < playerHand.Count(); i++)
     {
         playerHand[i] = new CardHand();
     }
     dealerHand  = new CardHand();
     cardDrawing = new CardDrawing(drawing);
     dealTo      = 0;
 }
Exemple #3
0
        public void FinishHand()
        {
            //Put the used card back to the shuffle machine.
            //This works exactly like skycity casino shuffle machine.
            machine.PutCardBack();
            //reset cards positions and card hand
            for (int i = 0; i < playerHand.Count(); i++)
            {
                playerHand[i] = new CardHand();
            }

            dealerHand    = new CardHand();
            cardDrawing   = new CardDrawing(drawing);
            lastBoxFinish = false;
            dealTo        = 0;
        }
Exemple #4
0
        public void Split()
        {
            playerBet[dealTo + 5].Playing    = true;               // set box number + 5 = true; which is use for spilt hand;
            playerBet[dealTo + 5].SplitedBet = true;
            playerBet[dealTo + 5].MainBet    = playerBet[dealTo].MainBet;
            Card firstCard  = playerHand[dealTo].FirstCard.Clone();
            Card secondCard = playerHand[dealTo].SecondCard.Clone();

            playerHand[dealTo]             = new CardHand();
            playerHand[dealTo].Splited     = true;
            playerHand[dealTo + 5].Splited = true;
            countCardValue(firstCard, playerHand[dealTo], dealTo);
            countCardValue(secondCard, playerHand[dealTo + 5], dealTo + 5);
            cardDrawing.SplitedCard(dealTo, firstCard, secondCard);
            //Debug.WriteLine("{0}--{1}", playerHand[dealTo].TotalCardValue, playerHand[dealTo + 5].TotalCardValue);
            checkTurn();
        }
Exemple #5
0
 private void displayPlayerOptions(int box, CardHand playerHand, bool splited = false)
 {
     this.Invoke(new DisplayOptionsDelegate(DisplayOptions), box, playerHand, splited);
 }
Exemple #6
0
        private GameResult getResult(CardHand dealerHand, CardHand playerHand)
        {
            GameResult result;

            if (playerHand.IsBust)
            {
                if (dealerHand.IsBlackJack)
                {
                    result = GameResult.LOSTBJ;
                }
                else
                {
                    result = GameResult.LOST;
                }
            }
            else if (dealerHand.IsBust)
            {
                if (playerHand.IsBlackJack)
                {
                    result = GameResult.WINBJ;
                }
                else
                {
                    result = GameResult.WIN;
                }
            }
            else if (dealerHand.IsBlackJack)      //if dealer is BJ
            {
                if (playerHand.IsBlackJack)       // if player is BJ then push
                {
                    result = GameResult.PUSH;
                }
                else
                {
                    result = GameResult.LOSTBJ;
                }
            }
            else if (playerHand.IsBlackJack)
            {
                if (dealerHand.IsBlackJack)
                {
                    result = GameResult.PUSH;
                }
                else
                {
                    result = GameResult.WINBJ;
                }
            }
            else
            {
                if (playerHand.TotalCardValue > dealerHand.TotalCardValue)
                {
                    result = GameResult.WIN;
                }
                else if (playerHand.TotalCardValue < dealerHand.TotalCardValue)
                {
                    result = GameResult.LOST;
                }
                else
                {
                    result = GameResult.PUSH;
                }
            }
            return(result);
        }
Exemple #7
0
        private void countCardValue(Card card, CardHand playerHand, int box)
        {
            string state = "";
            int    value = (int)card.CardRank;

            playerHand.OnTheGame = true;
            //If this is first card for this player,
            //Save this card for pair checking
            if (playerHand.CardsReceived < 1)
            {
                playerHand.FirstCard = card.Clone();
            }
            else if (playerHand.CardsReceived == 1)
            {
                playerHand.SecondCard = card.Clone();
            }

            if (value > 10) //All Picture cards count for value 10
            {
                value = 10;
            }

            //Ace can be value 1 or 11 depend on the total value of the hand;
            if (value == 1 && (playerHand.TotalCardValue + 11) <= 21)
            {
                value = 11;
                playerHand.SoftValue = true;
            }

            playerHand.TotalCardValue += value;
            playerHand.CardsReceived  += 1;

            if (playerHand.TotalCardValue > 21) //if total greater then 21, bust
            {
                playerHand.IsBust    = true;
                playerHand.OnTheGame = false;
            }

            if (playerHand.CardsReceived == 2 && playerHand.TotalCardValue == 21) //first 2 cards 21, this is BlackJack
            {
                if (playerHand.Splited == false)
                {
                    playerHand.IsBlackJack = true;
                }
            }

            // Check the state of the player up to the current card.
            if (playerHand.IsBlackJack == true)
            {
                state = "BJ";
            }
            else if (playerHand.IsBust == true)
            {
                state = "Bust";
            }
            else
            {
                state = playerHand.TotalCardValue.ToString();
            }
            // if this is the second card, check for pair
            if (playerHand.Splited == false)
            {
                if (playerHand.CardsReceived == 2)
                {
                    PairState pairState = checkPair(playerHand.FirstCard, card);
                    if (pairState != PairState.None)
                    {
                        playerHand.Pair = pairState;
                        //state = state + " " + pairState + " Pair";
                    }
                }
            }
            if (box < 5 || box == 10)
            {
                OutPutState(box, state);
            }
            else if (box >= 5 && box < 10)
            {
                if (this.playerHand[box - 5].IsBust)
                {
                    state += " -- " + "BUST";
                }
                else
                {
                    state += " -- " + this.playerHand[box - 5].TotalCardValue;
                }
                OutPutState(box - 5, state);
            }
        }