Ejemplo n.º 1
0
        private void DealerAI()
        {
            Hand dlr = players[1];

            currentTurnLbl.Text = "TURN: Dealer";
            descLbl.Text        = "Dealer is revealing their card...";
            Wait(1500);
            ShowDealerCard();
            dealerValueLbl.Text = "Value: " + dlr.calculateValue().ToString();
            Wait(1500);

            // If everyone has busted
            if ((plrBust == true) && (c1Bust == true) && (c2Bust == true) && (c3Bust == true))
            {
                descLbl.Text = "Everyone has busted, game over.";
                ShowDealerCard();
                dealerValueLbl.Text = "Final Value: " + dlr.calculateValue().ToString();
            }
            // If not everyone has busted
            else
            {
                descLbl.Text = "Dealer is deciding...";
                Wait(1500);

                if (int.Parse(dlr.calculateValue().ToString()) < 17)
                {
                    Wait(1500);
                    descLbl.Text = "Dealer has decided to hit.";
                    dlr.addCard(deck[0]);
                    deck.Remove(deck[0]);
                    dlr.showCards();
                    Wait(1500);
                    descLbl.Text = "Dealer is deciding...";
                    if (int.Parse(dlr.calculateValue().ToString()) < 17)
                    {
                        Wait(1500);
                        descLbl.Text = "Dealer has decided to hit.";
                        dlr.addCard(deck[0]);
                        deck.Remove(deck[0]);
                        dlr.showCards();
                        Wait(1500);
                        if (int.Parse(dlr.calculateValue().ToString()) > 21)
                        {
                            dlrTotal          = 0;
                            descLbl.Text      = "Dealer has busted.";
                            descLbl.ForeColor = Color.Red;
                            Wait(2000);
                            CalculateWinner();
                        }
                        else if (int.Parse(dlr.calculateValue().ToString()) < 21)
                        {
                            dlrTotal     = dlr.calculateValue();
                            descLbl.Text = "Dealer is deciding...";
                            Wait(1500);
                            descLbl.Text = "Dealer has decided to stand.";
                            Wait(1500);

                            CalculateWinner();
                        }
                    }
                    else if (int.Parse(dlr.calculateValue().ToString()) > 21)
                    {
                        dlrTotal          = 0;
                        descLbl.Text      = "Dealer has busted.";
                        descLbl.ForeColor = Color.Red;
                        Wait(2000);
                        ShowDealerCard();
                        dealerValueLbl.Text = "Final Value: " + dlr.calculateValue().ToString();
                        CalculateWinner();
                    }
                }
                else if (int.Parse(dlr.calculateValue().ToString()) >= 17)
                {
                    dlrTotal     = dlr.calculateValue();
                    descLbl.Text = "Dealer has decided to stand.";
                    Wait(1500);

                    CalculateWinner();
                }
            }
        }
Ejemplo n.º 2
0
        // Computer 1
        private void Computer1AI()
        {
            Wait(1500);
            descLbl.ForeColor   = Color.Black;
            descLbl.Text        = "Computer 1 is deciding...";
            currentTurnLbl.Text = "TURN: Computer 1";
            Wait(1500);
            c1Bust = false;

            Hand c1 = players[2];

            if (int.Parse(c1.calculateValue().ToString()) < 18)
            {
                descLbl.Text = "Computer 1 has decided to hit.";
                Wait(1000);
                c1.addCard(deck[0]);
                deck.Remove(deck[0]);
                c1.showCards();
                if (int.Parse(c1.calculateValue().ToString()) > 21)
                {
                    c1Total           = 0;
                    descLbl.Text      = "Computer 1 has busted.";
                    c1Bust            = true;
                    descLbl.ForeColor = Color.Red;
                    Wait(2000);
                    descLbl.ForeColor = Color.Black;
                    Computer2AI();
                }
                else if (int.Parse(c1.calculateValue().ToString()) <= 17)
                {
                    Wait(1500);
                    descLbl.Text = "Computer 1 is deciding...";
                    Wait(1500);
                    descLbl.Text = "Computer 1 has decided to hit.";
                    Wait(1000);
                    c1.addCard(deck[0]);
                    deck.Remove(deck[0]);
                    c1.showCards();
                    if (int.Parse(c1.calculateValue().ToString()) > 21)
                    {
                        c1Total           = 0;
                        descLbl.Text      = "Computer 1 has busted.";
                        c1Bust            = true;
                        descLbl.ForeColor = Color.Red;
                        Wait(2000);
                        descLbl.ForeColor = Color.Black;
                        Computer2AI();
                    }
                    else if (int.Parse(c1.calculateValue().ToString()) <= 21)
                    {
                        c1Total      = c1.calculateValue();
                        descLbl.Text = "Computer 1 is deciding...";
                        Wait(1500);
                        descLbl.Text = "Computer 1 has decided to stand.";
                        Wait(1500);
                        Computer2AI();
                    }
                }
                else
                {
                    c1Total = c1.calculateValue();
                    Wait(1500);
                    descLbl.Text = "Computer 1 is deciding...";
                    Wait(1500);
                    descLbl.Text = "Computer 1 has decided to stand.";
                    Wait(2000);
                    Computer2AI();
                }
            }
            else
            {
                c1Total           = c1.calculateValue();
                descLbl.ForeColor = Color.Black;
                Wait(1500);
                descLbl.Text = "Computer 1 has decided to stand.";
                Wait(2000);
                Computer2AI();
            }
        }
Ejemplo n.º 3
0
        // Computer 3
        private void Computer3AI()
        {
            if (computer3Lbl.Visible == true)
            {
                currentTurnLbl.Text = "TURN: Computer 3";
                descLbl.Text        = "Computer 3 is deciding...";
                Wait(1500);
                c3Bust = false;

                Hand c3 = players[4];

                if (int.Parse(c3.calculateValue().ToString()) < 18)
                {
                    descLbl.Text = "Computer 3 has decided to hit.";
                    Wait(1000);
                    c3.addCard(deck[0]);
                    deck.Remove(deck[0]);
                    c3.showCards();
                    if (int.Parse(c3.calculateValue().ToString()) > 21)
                    {
                        c3Total           = 0;
                        descLbl.Text      = "Computer 3 has busted.";
                        c3Bust            = true;
                        descLbl.ForeColor = Color.Red;
                        Wait(2000);
                        descLbl.ForeColor = Color.Black;
                        DealerAI();
                    }
                    else if (int.Parse(c3.calculateValue().ToString()) <= 17)
                    {
                        Wait(1500);
                        descLbl.Text = "Computer 3 is deciding...";
                        Wait(1500);
                        descLbl.Text = "Computer 3 has decided to hit.";
                        Wait(1000);
                        c3.addCard(deck[0]);
                        deck.Remove(deck[0]);
                        c3.showCards();
                        if (int.Parse(c3.calculateValue().ToString()) > 21)
                        {
                            c3Total           = 0;
                            descLbl.Text      = "Computer 3 has busted.";
                            c3Bust            = true;
                            descLbl.ForeColor = Color.Red;
                            Wait(2000);
                            descLbl.ForeColor = Color.Black;
                            DealerAI();
                        }
                        else if (int.Parse(c3.calculateValue().ToString()) <= 21)
                        {
                            c3Total      = c3.calculateValue();
                            descLbl.Text = "Computer 3 is deciding...";
                            Wait(1500);
                            descLbl.Text = "Computer 3 has decided to stand.";
                            Wait(1500);
                            DealerAI();
                        }
                    }
                    else
                    {
                        c3Total = c3.calculateValue();
                        Wait(1500);
                        descLbl.Text = "Computer 3 is deciding...";
                        Wait(1500);
                        descLbl.Text = "Computer 3 has decided to stand.";
                        Wait(2000);
                        DealerAI();
                    }
                }
                else
                {
                    c3Total           = c3.calculateValue();
                    descLbl.ForeColor = Color.Black;
                    Wait(1500);
                    descLbl.Text = "Computer 3 has decided to stand.";
                    DealerAI();
                }
            }
            // DEALER (NO COMPUTER 3)
            else
            {
                DealerAI();
            }
        }
Ejemplo n.º 4
0
        private void GetCards()
        {
            descLbl.Text = "The Dealer is giving everyone their cards.";
            Wait(1500);
            descLbl.Text = "";

            startCardsBtn.Hide();
            dealBtn.Show();
            standBtn.Show();


            valueLabel.Show();
            comp1ValueLbl.Show();

            if (computer2Lbl.Visible == true)
            {
                comp2ValueLbl.Show();
            }
            if (computer3Lbl.Visible == true)
            {
                comp2ValueLbl.Show();
                comp3ValueLbl.Show();
            }


            // player
            Hand h = players[0];

            h.cardObjects.Add(userCard1);
            h.cardObjects.Add(userCard2);
            h.valueLabel = valueLabel;
            h.winLoseLbl = winLoseLbl;
            h.dealBtn    = dealBtn;
            h.standBtn   = standBtn;
            h.isPlayer   = true;

            // player card dimensions
            h.cardX    = 131;
            h.cardY    = 194;
            h.cardLeft = 11;
            h.cardTop  = 539;
            h.cardSep  = 14;

            h.showCards();

            // dealer
            Hand dlr = players[1];

            dlr.cardObjects.Add(dealerCard1);
            dlr.cardObjects.Add(dealerCard2);
            dlr.valueLabel = dealerValueLbl;
            dlr.winLoseLbl = dealerBustLbl;
            dlr.dealBtn    = dealBtn;
            dlr.standBtn   = standBtn;
            dlr.isDealer   = true;

            // dealer card dimensions
            dlr.cardX    = 107;
            dlr.cardY    = 141;
            dlr.cardLeft = 377;
            dlr.cardTop  = 50;
            dlr.cardSep  = 13;

            dlr.showCards();

            Hand comp1 = players[2];

            comp1.cardObjects.Add(com1Card1);
            comp1.cardObjects.Add(com1Card2);
            comp1.valueLabel = comp1ValueLbl;
            comp1.winLoseLbl = comp1Bust;
            comp1.dealBtn    = dealBtn;
            comp1.standBtn   = standBtn;

            // computer 1 card dimensions
            comp1.cardX    = 83;
            comp1.cardY    = 117;
            comp1.cardLeft = 890;
            comp1.cardTop  = 158;
            comp1.cardSep  = 16;

            comp1.showCards();

            if (computer2Lbl.Visible == true)
            {
                // computer 2
                Hand comp2 = players[3];
                comp2.cardObjects.Add(com2Card1);
                comp2.cardObjects.Add(com2Card2);
                comp2.valueLabel = comp2ValueLbl;
                comp2.winLoseLbl = comp2Bust;
                comp2.dealBtn    = dealBtn;
                comp2.standBtn   = standBtn;

                // computer 2 card dimensions
                comp2.cardX    = 83;
                comp2.cardY    = 117;
                comp2.cardLeft = 890;
                comp2.cardTop  = 309;
                comp2.cardSep  = 16;

                comp2.showCards();
            }

            if (computer3Lbl.Visible == true)
            {
                // computer 3
                Hand comp3 = players[4];
                comp3.cardObjects.Add(com3Card1);
                comp3.cardObjects.Add(com3Card2);
                comp3.valueLabel = comp3ValueLbl;
                comp3.winLoseLbl = comp3Bust;
                comp3.dealBtn    = dealBtn;
                comp3.standBtn   = standBtn;

                // computer 3 card dimensions
                comp3.cardX    = 83;
                comp3.cardY    = 117;
                comp3.cardLeft = 890;
                comp3.cardTop  = 464;
                comp3.cardSep  = 16;

                comp3.showCards();
            }

            currentTurnLbl.Text = "TURN: " + nameBox.Text;
            descLbl.Text        = "It is your turn.";
        }