Пример #1
0
        // Stand button
        private void standBtn_Click(object sender, EventArgs e)
        {
            Hand h = players[0];

            plrTotal         = h.calculateValue();
            standBtn.Enabled = false;
            dealBtn.Enabled  = false;
            descLbl.Text     = "You have chosen to stand.";
            Wait(1500);

            Computer1AI();
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Hand h = players[0];

            h.addCard(deck[0]);
            deck.Remove(deck[0]);

            h.showCards();

            descLbl.Text = "You have chosen to hit.";
            Wait(1500);
            descLbl.Text = "It is your turn.";

            if (int.Parse(h.calculateValue().ToString()) > 21)
            {
                plrTotal          = 0;
                descLbl.Text      = "You have busted...";
                plrBust           = true;
                descLbl.ForeColor = Color.Red;
                Wait(2000);
                Computer1AI();
            }
        }
Пример #3
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();
                }
            }
        }
Пример #4
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();
            }
        }
Пример #5
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();
            }
        }