Example #1
0
        private void dealHand()
        {
            baccHand currentHand = currentShoe.Dequeue();

            playerCard1.Text = currentHand.player1.blackjackValue.ToString();
            playerCard2.Text = currentHand.player2.blackjackValue.ToString();
            if (currentHand.player3.blackjackValue == 0)
            {
                playerCard3.Text = "No Draw";
            }
            else if (currentHand.player3.blackjackValue == -1)
            {
                playerCard3.Text = "Error";
            }
            else
            {
                playerCard3.Text = currentHand.player3.blackjackValue.ToString();
            }

            bankerCard1.Text = currentHand.banker1.blackjackValue.ToString();
            bankerCard2.Text = currentHand.banker2.blackjackValue.ToString();
            if (currentHand.banker3.blackjackValue == 0)
            {
                bankerCard3.Text = "No Draw";
            }
            else if (currentHand.banker3.blackjackValue == -1)
            {
                bankerCard3.Text = "Error";
            }
            else
            {
                bankerCard3.Text = currentHand.banker3.blackjackValue.ToString();
            }

            bankerResult.Text = currentHand.bankerTotal.ToString();
            playerResult.Text = currentHand.playerTotal.ToString();

            switch (currentHand.result)
            {
            case HandResult.Banker:
                resultText.Text = "Banker Wins";
                bankerCounter++;
                break;

            case HandResult.Player:
                resultText.Text = "Player Wins";
                playerCounter++;
                break;

            case HandResult.Tie:
                resultText.Text = "Tie Hand";
                tieCounter++;
                break;

            case HandResult.Error:
                resultText.Text = "!!! Error Hand !!!";
                break;

            default:
                resultText.Text = "default View error";
                break;
            }

            handBet(currentHand.result);

            bankerOneImage.Source = new BitmapImage(new Uri(currentHand.banker1.imageSourceString, UriKind.Relative));
            bankerTwoImage.Source = new BitmapImage(new Uri(currentHand.banker2.imageSourceString, UriKind.Relative));

            playerOneImage.Source = new BitmapImage(new Uri(currentHand.player1.imageSourceString, UriKind.Relative));
            playerTwoImage.Source = new BitmapImage(new Uri(currentHand.player2.imageSourceString, UriKind.Relative));


            if (currentHand.banker3.blackjackValue == 0)
            {
                bankerThreeImage.Source = new BitmapImage(new Uri($@"/images/card deck/back-blue-2.png", UriKind.Relative));
            }
            else
            {
                bankerThreeImage.Source = new BitmapImage(new Uri(currentHand.banker3.imageSourceString, UriKind.Relative));
            }

            if (currentHand.player3.blackjackValue == 0)
            {
                playerThreeImage.Source = new BitmapImage(new Uri($@"/images/card deck/back-blue-2.png", UriKind.Relative));
            }
            else
            {
                playerThreeImage.Source = new BitmapImage(new Uri(currentHand.player3.imageSourceString, UriKind.Relative));
            }

            handCount++;
            handCountTextBlock.Text   = handCount.ToString();
            bankerCountTextBlock.Text = bankerCounter.ToString();
            playerCountTextBlock.Text = playerCounter.ToString();
            tieCountTextBlock.Text    = tieCounter.ToString();
        }
Example #2
0
        private static baccHand theHand()
        {
            var currentHand = new baccHand();
            var player1     = mainShoe.Dequeue();
            var banker1     = mainShoe.Dequeue();
            var player2     = mainShoe.Dequeue();
            var banker2     = mainShoe.Dequeue();

            Card banker3 = new Card();
            Card player3 = new Card();


            currentHand.bankerTotal = banker1.blackjackValue + banker2.blackjackValue;
            currentHand.playerTotal = player1.blackjackValue + player2.blackjackValue;


            // check natural 9
            if (currentHand.playerTotal == 9 || currentHand.bankerTotal == 9)
            {
                currentHand.banker1 = banker1;
                currentHand.banker2 = banker2;
                currentHand.banker3 = banker3;
                currentHand.player1 = player1;
                currentHand.player2 = player2;
                currentHand.player3 = player3;

                if (currentHand.playerTotal == currentHand.bankerTotal)
                {
                    //return tie
                    currentHand.result = HandResult.Tie;
                }
                if (currentHand.playerTotal == 9 && currentHand.playerTotal > currentHand.bankerTotal)
                {
                    // player win natural 9
                    currentHand.result = HandResult.Player;
                }
                if (currentHand.bankerTotal == 9 && currentHand.bankerTotal > currentHand.playerTotal)
                {
                    // banker win natural 9
                    currentHand.result = HandResult.Banker;
                }
                currentHand.playerTotal = currentHand.playerTotal;
                currentHand.bankerTotal = currentHand.bankerTotal;

                return(currentHand);
            }

            // natural 8
            if (currentHand.playerTotal == 8 || currentHand.bankerTotal == 8)
            {
                currentHand.banker1 = banker1;
                currentHand.banker2 = banker2;
                currentHand.banker3 = banker3;
                currentHand.player1 = player1;
                currentHand.player2 = player2;
                currentHand.player3 = player3;

                if (currentHand.playerTotal == currentHand.bankerTotal)
                {
                    //return tie
                    currentHand.result = HandResult.Tie;
                }
                if (currentHand.playerTotal == 8 && currentHand.playerTotal > currentHand.bankerTotal)
                {
                    // player win natural 8
                    currentHand.result = HandResult.Player;
                }
                if (currentHand.bankerTotal == 8 && currentHand.bankerTotal > currentHand.playerTotal)
                {
                    // banker win natural 8
                    currentHand.result = HandResult.Banker;
                }

                currentHand.playerTotal = currentHand.playerTotal;
                currentHand.bankerTotal = currentHand.bankerTotal;

                return(currentHand);
            }

            //player 6 or 7 no draw or check

            //player 0 - 5 draw

            if (currentHand.playerTotal <= 5)
            {
                player3 = mainShoe.Dequeue();

                currentHand.playerTotal += player3.blackjackValue;
            }


            //banker draws
            //no draw on 7
            //check  win
            if (currentHand.bankerTotal == 7)
            {
                currentHand.banker1 = banker1;
                currentHand.banker2 = banker2;
                currentHand.banker3 = banker3;

                currentHand.player1 = player1;
                currentHand.player2 = player2;
                currentHand.player3 = player3;



                if (currentHand.bankerTotal == currentHand.playerTotal)
                {
                    //tie hand
                    currentHand.result = HandResult.Tie;
                }
                else if (currentHand.bankerTotal > currentHand.playerTotal)
                {
                    //bank win
                    currentHand.result = HandResult.Banker;
                }
                else if (currentHand.bankerTotal < currentHand.playerTotal)
                {
                    //player win
                    currentHand.result = HandResult.Player;
                }
                else
                {
                    //error
                    currentHand.result = HandResult.Error;
                }

                currentHand.bankerTotal = currentHand.bankerTotal;
                currentHand.playerTotal = currentHand.playerTotal;
                return(currentHand);
            }

            if (currentHand.bankerTotal == 6)
            {
                //6 draws

                if (player3.blackjackValue == 6 || player3.blackjackValue == 7)
                {
                    banker3 = mainShoe.Dequeue();
                    currentHand.bankerTotal += banker3.blackjackValue;
                }


                currentHand.banker1 = banker1;
                currentHand.banker2 = banker2;
                currentHand.banker3 = banker3;

                currentHand.player1 = player1;
                currentHand.player2 = player2;
                currentHand.player3 = player3;


                //6 check
                if (currentHand.bankerTotal == currentHand.playerTotal)
                {
                    //tie
                    currentHand.result = HandResult.Tie;
                }
                else if (currentHand.bankerTotal > currentHand.playerTotal)
                {
                    //banker win
                    currentHand.result = HandResult.Banker;
                }
                else if (currentHand.bankerTotal < currentHand.playerTotal)
                {
                    //player win
                    currentHand.result = HandResult.Player;
                }
                else
                {
                    currentHand.result = HandResult.Error;
                }

                currentHand.bankerTotal = currentHand.bankerTotal;
                currentHand.playerTotal = currentHand.playerTotal;

                return(currentHand);
            }
            //5 draws

            if (currentHand.bankerTotal == 5)
            {
                if (player3.blackjackValue >= 4 && player3.blackjackValue <= 7 || player3.blackjackValue == 0)
                {
                    banker3 = mainShoe.Dequeue();
                    currentHand.bankerTotal += banker3.blackjackValue;
                }

                currentHand.banker1 = banker1;
                currentHand.banker2 = banker2;
                currentHand.banker3 = banker3;

                currentHand.player1 = player1;
                currentHand.player2 = player2;
                currentHand.player3 = player3;


                //5 check
                if (currentHand.bankerTotal == currentHand.playerTotal)
                {
                    //tie
                    currentHand.result = HandResult.Tie;
                }
                else if (currentHand.bankerTotal > currentHand.playerTotal)
                {
                    //banker win
                    currentHand.result = HandResult.Banker;
                }
                else if (currentHand.bankerTotal < currentHand.playerTotal)
                {
                    //player win
                    currentHand.result = HandResult.Player;
                }
                else
                {
                    currentHand.result = HandResult.Error;
                }

                currentHand.bankerTotal = currentHand.bankerTotal;
                currentHand.playerTotal = currentHand.playerTotal;

                return(currentHand);
            }

            if (currentHand.bankerTotal == 4)
            {
                //4 draws

                if (player3.blackjackValue >= 2 && player3.blackjackValue <= 7 || player3.blackjackValue == 0)
                {
                    banker3 = mainShoe.Dequeue();
                    currentHand.bankerTotal += banker3.blackjackValue;
                }


                currentHand.banker1 = banker1;
                currentHand.banker2 = banker2;
                currentHand.banker3 = banker3;

                currentHand.player1 = player1;
                currentHand.player2 = player2;
                currentHand.player3 = player3;


                //4 check
                if (currentHand.bankerTotal == currentHand.playerTotal)
                {
                    //tie
                    currentHand.result = HandResult.Tie;
                }
                else if (currentHand.bankerTotal > currentHand.playerTotal)
                {
                    //banker win
                    currentHand.result = HandResult.Banker;
                }
                else if (currentHand.bankerTotal < currentHand.playerTotal)
                {
                    //player win
                    currentHand.result = HandResult.Player;
                }
                else
                {
                    currentHand.result = HandResult.Error;
                }

                currentHand.bankerTotal = currentHand.bankerTotal;
                currentHand.playerTotal = currentHand.playerTotal;

                return(currentHand);
            }

            if (currentHand.bankerTotal == 3)
            {
                //3 draws
                if (player3.blackjackValue != 8)
                {
                    banker3 = mainShoe.Dequeue();
                    currentHand.bankerTotal += banker3.blackjackValue;
                }


                currentHand.banker1 = banker1;
                currentHand.banker2 = banker2;
                currentHand.banker3 = banker3;

                currentHand.player1 = player1;
                currentHand.player2 = player2;
                currentHand.player3 = player3;


                //3 check
                if (currentHand.bankerTotal == currentHand.playerTotal)
                {
                    //tie
                    currentHand.result = HandResult.Tie;
                }
                else if (currentHand.bankerTotal > currentHand.playerTotal)
                {
                    //banker win
                    currentHand.result = HandResult.Banker;
                }
                else if (currentHand.bankerTotal < currentHand.playerTotal)
                {
                    //player win
                    currentHand.result = HandResult.Player;
                }
                else
                {
                    currentHand.result = HandResult.Error;
                }


                currentHand.bankerTotal = currentHand.bankerTotal;
                currentHand.playerTotal = currentHand.playerTotal;

                return(currentHand);
            }

            if (currentHand.bankerTotal <= 2)
            {
                //0, 1, 2 draws
                if (currentHand.bankerTotal <= 2)
                {
                    banker3 = mainShoe.Dequeue();
                    currentHand.bankerTotal += banker3.blackjackValue;
                }


                currentHand.banker1 = banker1;
                currentHand.banker2 = banker2;
                currentHand.banker3 = banker3;

                currentHand.player1 = player1;
                currentHand.player2 = player2;
                currentHand.player3 = player3;


                //0, 1, 2 check
                if (currentHand.bankerTotal == currentHand.playerTotal)
                {
                    //tie
                    currentHand.result = HandResult.Tie;
                }
                else if (currentHand.bankerTotal > currentHand.playerTotal)
                {
                    //banker win
                    currentHand.result = HandResult.Banker;
                }
                else if (currentHand.bankerTotal < currentHand.playerTotal)
                {
                    //player win
                    currentHand.result = HandResult.Player;
                }
                else
                {
                    currentHand.result = HandResult.Error;
                }

                currentHand.bankerTotal = currentHand.bankerTotal;
                currentHand.playerTotal = currentHand.playerTotal;

                return(currentHand);
            }

            return(currentHand);
        }