示例#1
0
        public static void MakeComputerMove(ref int pMoney, ref int cMoney, ref int pMoneyBet, ref int cMoneyBet, NumericUpDown numericBet, Card[] cards, Card[] pHand, Card[] computerHand, List <Card> table, PictureBox[] picturesPHand, PictureBox[] picturesTable, PictureBox[] picturesCHand, Label lblCMoneyValue, Label lblPMoneyValue, Label lblCMoneyBetValue, Label lblPMoneyBetValue, Button btnBet, Button btnCall, Button btnFold, Button btnCheck, ToolStripMenuItem continueToolStripMenuItem)
        {
            int randonNum;

            if (pMoney == 0 || cMoney == 0)
            {
                if (pMoneyBet > cMoneyBet)
                {
                    MessageBox.Show("computer called");
                    Moves.Call(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, 'c');
                }
                else
                {
                    MessageBox.Show("computer checked");
                }
                MessageBox.Show("All in");
                Card.DisableBtnsEnableContinue(btnBet, btnCall, btnFold, btnCheck, continueToolStripMenuItem);
                continueToolStripMenuItem.Enabled = false;
                while (table.Count < 5)
                {
                    //Thread.Sleep(1000);
                    Card.DealAnotherCard(table, cards);
                }
                Card.UpdateAll
                (
                    numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, cMoney, pMoney, cMoneyBet, pMoneyBet,
                    bigStake
                );
                Card.SetComputerCardPicturesToRed(picturesCHand);
                int[] computerRank = Card.RankHand(table, computerHand);
                int[] playerRank   = Card.RankHand(table, pHand);
                char  winner       = Card.DetermineWinner(playerRank, computerRank);
                Card.DistributeMoneyBasedOnWinner(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, winner);
                Card.UpdateAll
                (
                    numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, cMoney, pMoney, cMoneyBet, pMoneyBet,
                    bigStake
                );
                Card.DisableBtnsEnableContinue(btnBet, btnCall, btnFold, btnCheck, continueToolStripMenuItem);
            }
            else if (pStarts)
            {
                if (pMoneyBet == cMoneyBet)
                {
                    randonNum = rnd.Next(1, 11);
                    if (randonNum > 5 && pMoney >= cMoney / 100 && miniRound < 3)
                    {
                        int bigNumOfRandom = 100;
                        int amountToBet    = 0;
                        do
                        {
                            amountToBet = rnd.Next(1, bigNumOfRandom) * cMoney / 100 + (pMoneyBet - cMoneyBet);
                            bigNumOfRandom--;
                        } while (amountToBet > Math.Min(pMoney, cMoney));
                        Bet(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, 'c', amountToBet);
                        btnBet.Enabled   = false;
                        btnCall.Enabled  = true;
                        btnCheck.Enabled = false;
                        string whatToShow = string.Format("computer has betted " + amountToBet);
                        MessageBox.Show(whatToShow);
                        miniRound++;
                    }
                    else
                    {
                        if (table.Count < 5)
                        {
                            Card.DealAnotherCard(table, cards);
                            Card.UpdateAll
                            (
                                numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, cMoney, pMoney, cMoneyBet, pMoneyBet,
                                bigStake
                            );
                            Card.SetComputerCardPicturesToRed(picturesCHand);
                            MessageBox.Show("Computer Checked");
                            miniRound        = 1;
                            btnCheck.Enabled = true;
                            btnBet.Enabled   = true;
                            btnCall.Enabled  = false;
                        }
                        else
                        {
                            Card.DisableBtnsEnableContinue(btnBet, btnCall, btnFold, btnCheck, continueToolStripMenuItem);
                            int[] computerRank = Card.RankHand(table, computerHand);
                            int[] playerRank   = Card.RankHand(table, pHand);
                            char  winner       = Card.DetermineWinner(playerRank, computerRank);
                            Card.DistributeMoneyBasedOnWinner(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, winner);
                            Card.UpdateAll
                            (
                                numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, cMoney, pMoney, cMoneyBet, pMoneyBet,
                                bigStake
                            );
                        }
                    }
                }
                else
                {
                    randonNum = rnd.Next(1, 11);
                    if (randonNum > 8)
                    {
                        MessageBox.Show("computer folded");
                        Fold(numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, ref cMoney, ref pMoney, ref cMoneyBet, ref pMoneyBet, bigStake, btnBet, btnCall, btnFold, btnCheck, continueToolStripMenuItem, 'p');
                    }
                    else if (randonNum > 4 && randonNum < 9)
                    {
                        Moves.Call(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, 'c');
                        MessageBox.Show("computer called");
                        if (table.Count == 5)
                        {
                            Card.DisableBtnsEnableContinue(btnBet, btnCall, btnFold, btnCheck, continueToolStripMenuItem);
                            int[] computerRank = Card.RankHand(table, computerHand);
                            int[] playerRank   = Card.RankHand(table, pHand);
                            char  winner       = Card.DetermineWinner(playerRank, computerRank);
                            Card.DistributeMoneyBasedOnWinner(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, winner);
                            Card.UpdateAll
                            (
                                numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, cMoney, pMoney, cMoneyBet, pMoneyBet,
                                bigStake
                            );
                        }
                        else
                        {
                            Card.DealAnotherCard(table, cards);
                            Card.UpdateAll
                            (
                                numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, cMoney, pMoney, cMoneyBet, pMoneyBet,
                                bigStake
                            );
                            Card.SetComputerCardPicturesToRed(picturesCHand);
                            miniRound        = 1;
                            btnCheck.Enabled = true;
                            btnBet.Enabled   = true;
                        }
                    }
                    else
                    {
                        if (pMoney >= cMoney / 100)
                        {
                            try
                            {
                                int bigNumOfRandom = 100;
                                int amountToBet    = 0;
                                do
                                {
                                    amountToBet = rnd.Next(1, bigNumOfRandom) * cMoney / 100 + (pMoneyBet - cMoneyBet);
                                    bigNumOfRandom--;
                                } while (amountToBet > Math.Min(pMoney, cMoney));
                                Bet(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, 'c', amountToBet);
                                btnBet.Enabled   = false;
                                btnCall.Enabled  = true;
                                btnCheck.Enabled = false;
                                string whatToShow = string.Format("computer has betted " + amountToBet);
                                MessageBox.Show(whatToShow);
                                miniRound++;
                            }
                            catch
                            {
                                Moves.Call(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, 'c');
                                MessageBox.Show("computer called");
                                Card.DealAnotherCard(table, cards);
                                Card.UpdateAll
                                (
                                    numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, cMoney, pMoney, cMoneyBet, pMoneyBet,
                                    bigStake
                                );
                                Card.SetComputerCardPicturesToRed(picturesCHand);
                                miniRound        = 1;
                                btnCheck.Enabled = true;
                                btnBet.Enabled   = true;
                            }
                        }
                        else
                        {
                            Moves.Call(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, 'c');
                            MessageBox.Show("computer called");
                            Card.DealAnotherCard(table, cards);
                            Card.UpdateAll
                            (
                                numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, cMoney, pMoney, cMoneyBet, pMoneyBet,
                                bigStake
                            );
                            Card.SetComputerCardPicturesToRed(picturesCHand);
                            miniRound        = 1;
                            btnCheck.Enabled = true;
                            btnBet.Enabled   = true;
                        }
                    }
                }
            }

            //if !pStarts
            else
            {
                switch (miniRound)
                {
                case 1:
                    randonNum = rnd.Next(1, 11);
                    if (randonNum < 8)
                    {
                        //call
                        if (table.Count == 3)
                        {
                            Moves.Call(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, 'c');
                            MessageBox.Show("computer called");
                        }
                        else
                        {
                            MessageBox.Show("computer checked");
                        }
                        btnCall.Enabled = false;
                    }
                    else
                    {
                        //If the player has at least 1 precent money than the computer, bet a random amount between 1 to 20 precent.
                        if (pMoney >= cMoney / 100)
                        {
                            try
                            {
                                int bigNumOfRandom = 21;
                                int amountToBet    = 0;
                                do
                                {
                                    amountToBet = rnd.Next(1, bigNumOfRandom) * cMoney / 100 + (pMoneyBet - cMoneyBet);
                                    bigNumOfRandom--;
                                } while (amountToBet > Math.Min(pMoney, cMoney));
                                Bet(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, 'c', amountToBet);
                                btnCheck.Enabled = false;
                                btnBet.Enabled   = false;
                                btnCall.Enabled  = true;
                                string whatToShow = string.Format("computer has betted " + amountToBet);
                                MessageBox.Show(whatToShow);
                            }
                            catch
                            {
                                MessageBox.Show("computer checked");
                                btnCall.Enabled = false;
                            }
                        }
                        else
                        {
                            if (table.Count == 3)
                            {
                                Moves.Call(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, 'c');
                                MessageBox.Show("computer called");
                            }
                            else
                            {
                                MessageBox.Show("computer checked");
                                btnCall.Enabled = false;
                            }
                        }
                    }
                    miniRound++;
                    break;

                case 3:
                    randonNum = rnd.Next(1, 11);
                    if (randonNum > 9)
                    {
                        Fold(numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, ref cMoney, ref pMoney, ref cMoneyBet, ref pMoneyBet, bigStake, btnBet, btnCall, btnFold, btnCheck, continueToolStripMenuItem, 'p');
                    }
                    else
                    {
                        Moves.Call(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, 'c');
                        MessageBox.Show("computer called");
                        if (table.Count == 5)
                        {
                            Card.DisableBtnsEnableContinue(btnBet, btnCall, btnFold, btnCheck, continueToolStripMenuItem);
                            int[] computerRank = Card.RankHand(table, computerHand);
                            int[] playerRank   = Card.RankHand(table, pHand);
                            char  winner       = Card.DetermineWinner(playerRank, computerRank);
                            Card.DistributeMoneyBasedOnWinner(ref pMoney, ref cMoney, ref pMoneyBet, ref cMoneyBet, winner);
                            Card.UpdateAll
                            (
                                numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, cMoney, pMoney, cMoneyBet, pMoneyBet,
                                bigStake
                            );
                        }
                        else
                        {
                            Card.DealAnotherCard(table, cards);
                            Card.UpdateAll(numericBet, pHand, computerHand, table, picturesPHand, picturesTable, picturesCHand, lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, cMoney, pMoney, cMoneyBet, pMoneyBet, bigStake);
                            Card.SetComputerCardPicturesToRed(picturesCHand);
                            miniRound = 1;
                        }
                    }
                    break;
                }
            }
            if (cMoney == 0)
            {
                btnBet.Enabled = false;
            }
            Card.UpdateNumeric(numericBet, cMoney, pMoney, bigStake, cMoneyBet, pMoneyBet);
            Card.UpdateMoney(lblCMoneyValue, lblPMoneyValue, lblCMoneyBetValue, lblPMoneyBetValue, cMoney, pMoney, cMoneyBet, pMoneyBet);
        }