Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            pl1.IsLoose = true;

            picturePl1.Image = null;
            picturePl1.Refresh();
            picturePl2.Image = null;
            picturePl2.Refresh();

            AcceptRateButton.Visible = false;
            AcceptRateButton.Refresh();
            UpRateButton.Visible = false;
            UpRateButton.Refresh();
            DownRateButton.Visible = false;
            DownRateButton.Refresh();
            textBoxRate.Visible = false;
            textBoxRate.Refresh();
            riseButton.Visible = false;
            riseButton.Refresh();
            FallDownButton.Visible = false;
            FallDownButton.Refresh();

            solutionOfPlayer = 1;

            pl1.ShowRate(this);

            Trade();
        }
Ejemplo n.º 2
0
        private void AcceptRateButton_Click(object sender, EventArgs e)
        {
            if (pl1.Account + pl1.Rate > maxRate)
            {
                pl1.Account -= maxRate - pl1.Rate;
                pl1.Rate     = maxRate;
            }
            else
            {
                pl1.AllIn   = true;
                pl1.Rate    = pl1.Account + pl1.Rate;
                pl1.Account = 0;
            }

            AcceptRateButton.Visible = false;
            AcceptRateButton.Refresh();
            UpRateButton.Visible = false;
            UpRateButton.Refresh();
            DownRateButton.Visible = false;
            DownRateButton.Refresh();
            textBoxRate.Visible = false;
            textBoxRate.Refresh();

            riseButton.Visible = false;
            riseButton.Refresh();

            FallDownButton.Visible = false;
            FallDownButton.Refresh();

            solutionOfPlayer = 1;

            pl1.ShowRate(this);

            Trade();
        }
Ejemplo n.º 3
0
        private void checkButton_Click(object sender, EventArgs e)
        {
            if (pl1.Rate == maxRate)
            {
                lblPlRate.Text = pl1.Rate.ToString();
                lblPlRate.Refresh();

                if (pl1.IsLoose)
                {
                    picturePl1.Image = null;
                    picturePl1.Refresh();
                    picturePl2.Image = null;
                    picturePl2.Refresh();
                }

                if (bot1.IsLoose)
                {
                    pictureBot11.Image = null;
                    pictureBot11.Refresh();
                    pictureBot12.Image = null;
                    pictureBot12.Refresh();
                }

                if (bot2.IsLoose)
                {
                    pictureBot21.Image = null;
                    pictureBot21.Refresh();
                    pictureBot22.Image = null;
                    pictureBot22.Refresh();
                }

                AcceptRateButton.Visible = false;
                AcceptRateButton.Refresh();
                UpRateButton.Visible = false;
                UpRateButton.Refresh();
                DownRateButton.Visible = false;
                DownRateButton.Refresh();
                textBoxRate.Visible = false;
                textBoxRate.Refresh();
                riseButton.Visible = false;
                riseButton.Refresh();
                FallDownButton.Visible = false;
                FallDownButton.Refresh();

                solutionOfPlayer = 1;

                Trade();
            }
        }
Ejemplo n.º 4
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        private void Trade()
        {
LABEL1:

            Player p = new Player();

            if (solutionOfPlayer == 0)                                        ///////////////////////////////////////////////// before word of Player (I)
            {
                for (int i = indexOfRisedPlayer + 1; i <= indexOfPlayer; i++) // если был райз, слово игроку после игрока, сделавшего райз
                {
                    if (players[i].Name.Equals("Computer1") && !players[i].IsLoose)
                    {
                        if (RemainderOnePlayer(ref p))
                        {
                            solutionOfPlayer = 1;
                            break;
                        }
                        if (!players[i].AllIn)
                        {
                            string s = players[i].AcceptSolution(this, sequenceOfGame, set, ref maxRate);

                            if (s.Equals("raise") || s.Equals("raise all in"))
                            {
                                ChangeSequenceOfPlayers(i);               // если райз - сделать этого игрока первым в списке торгов
                                riseIsOccured      = "";
                                indexOfRisedPlayer = 0;
                                goto LABEL1;
                            }
                        }
                    }

                    else if (players[i].Name.Equals("Computer2") && !players[i].IsLoose)
                    {
                        if (RemainderOnePlayer(ref p))
                        {
                            solutionOfPlayer = 1;
                            break;
                        }

                        if (!players[i].AllIn)
                        {
                            string s = players[i].AcceptSolution(this, sequenceOfGame, set, ref maxRate);

                            if (s.Equals("raise") || s.Equals("raise all in"))
                            {
                                ChangeSequenceOfPlayers(i);               // если райз - сделать этого игрока первым в списке торгов
                                riseIsOccured      = "";
                                indexOfRisedPlayer = 0;
                                goto LABEL1;
                            }
                        }
                    }

                    else if (players[i].Name.Equals("Player"))
                    {
                        if (RemainderOnePlayer(ref p))
                        {
                            solutionOfPlayer = 1;
                            break;
                        }
                        indexOfPlayer = i;

                        if (players[i].IsLoose || players[i].AllIn || players[i].IsDefault)
                        {
                            solutionOfPlayer = 1;                   // если Игрок упал - переход ко 2-й части торгов без его участия
                        }
                        else
                        {
                            AcceptRateButton.Visible = true;
                            AcceptRateButton.Refresh();
                            UpRateButton.Visible = true;
                            UpRateButton.Refresh();
                            DownRateButton.Visible = true;
                            DownRateButton.Refresh();
                            textBoxRate.Visible = true;
                            textBoxRate.Text    = 0.ToString();
                            textBoxRate.Refresh();
                            riseButton.Visible = true;
                            riseButton.Refresh();
                            FallDownButton.Visible = true;
                            FallDownButton.Refresh();
                            break;
                        }
                    }
                }
                if (pl1.IsDefault)
                {
                    solutionOfPlayer   = 1;
                    indexOfRisedPlayer = 2;
                }
            }
            //////////////////////////////////////////////////////////////////////////////////

            if (solutionOfPlayer == 1)          ///////////////////////////////// after word of Player (I)
            {
                if (!riseIsOccured.Equals(""))  // if was Rise of Player
                {
                    ChangeSequenceOfPlayers(Convert.ToInt32(riseIsOccured));
                    riseIsOccured      = "";
                    solutionOfPlayer   = 1;
                    indexOfRisedPlayer = -1;
                    goto LABEL1;
                }

                for (int i = indexOfPlayer + 1; i < players.Count; i++)
                {
                    if (players[i].Name.Equals("Computer1") && !players[i].IsLoose)
                    {
                        if (RemainderOnePlayer(ref p))
                        {
                            solutionOfPlayer = 1;
                            break;
                        }
                        if (!players[i].AllIn)
                        {
                            string s = players[i].AcceptSolution(this, sequenceOfGame, set, ref maxRate);

                            if (s.Equals("raise") || s.Equals("raise all in"))
                            {
                                ChangeSequenceOfPlayers(i);               // если райз - сделать этого игрока первым в списке торгов
                                riseIsOccured      = "";
                                indexOfRisedPlayer = 0;

                                solutionOfPlayer = 0;

                                goto LABEL1;
                            }
                        }
                    }

                    else if (players[i].Name.Equals("Computer2") && !players[i].IsLoose)
                    {
                        if (RemainderOnePlayer(ref p))
                        {
                            solutionOfPlayer = 1;
                            break;
                        }

                        if (!players[i].AllIn)
                        {
                            string s = players[i].AcceptSolution(this, sequenceOfGame, set, ref maxRate);

                            if (s.Equals("raise") || s.Equals("raise all in"))
                            {
                                ChangeSequenceOfPlayers(i);               // если райз - сделать этого игрока первым в списке торгов
                                riseIsOccured      = "";
                                indexOfRisedPlayer = 0;

                                solutionOfPlayer = 0;

                                goto LABEL1;
                            }
                        }
                    }
                }

                for (int i = 0; i < players.Count; i++)
                {
                    bank += players[i].Rate;
                    players[i].Contribution += players[i].Rate;
                }

                lblBank.Text = bank.ToString();
                lblBank.Refresh();

                lblPlRate.Text    = "";
                lblComp1Rate.Text = "";
                lblComp2Rate.Text = "";
                lblPlRate.Refresh();
                lblComp1Rate.Refresh();
                lblComp2Rate.Refresh();

                if (RemainderOnePlayer(ref p))                          // if all players fold but one
                {
                    MessageBox.Show(p.Name + " WON!");
                    sequenceOfGame = -1;

                    for (int i = 0; i < players.Count; i++)
                    {
                        if (players[i].Name.Equals(p.Name))
                        {
                            players[i].Account += players[i].Contribution;
                        }
                        else
                        {
                            if (p.Contribution >= players[i].Contribution)
                            {
                                p.Account += players[i].Contribution;
                            }
                            else
                            {
                                p.Account          += p.Contribution;
                                players[i].Account += players[i].Contribution - p.Contribution;
                            }
                        }
                    }

                    p.ShowRate(this);

                    foreach (var item in players)
                    {
                        if (item.Account <= 0)
                        {
                            item.IsDefault = true;
                            MessageBox.Show(item.Name + " LOST");
                        }
                        item.AllIn        = false;
                        item.Contribution = 0;
                    }
                }

                else if (sequenceOfGame == 3)
                {
                    sequenceOfGame = -1;

                    label2.Text = "";
                    label3.Text = "";
                    label2.Refresh();
                    label3.Refresh();

                    winners = DefineWinners(set, players);
                    ShowWinners(set, winners);

                    if (winners.Count == 1)
                    {
                        for (int i = 0; i < players.Count; i++)
                        {
                            if (players[i].Name.Equals(winners[0].Name))
                            {
                                players[i].Account += players[i].Contribution;
                            }
                            else
                            {
                                if (winners[0].Contribution >= players[i].Contribution)
                                {
                                    winners[0].Account += players[i].Contribution;
                                }
                                else
                                {
                                    winners[0].Account += winners[0].Contribution;
                                    players[i].Account += players[i].Contribution - winners[0].Contribution;
                                }
                            }
                        }
                        winners[0].ShowRate(this);
                    }

                    else if (winners.Count == 2)
                    {
                        int countOfPlayersInGame = 0;
                        for (int i = 0; i < players.Count; i++)
                        {
                            if (!players[i].IsLoose && !players[i].IsDefault)
                            {
                                countOfPlayersInGame++;
                            }
                        }

                        if (countOfPlayersInGame == 3)
                        {
                            Player losedPlayer = null;

                            for (int i = 0; i < players.Count; i++)   // find looser
                            {
                                if (!winners.Contains(players[i]))
                                {
                                    losedPlayer = players[i];
                                }
                            }
                            if (winners[0].Contribution > winners[1].Contribution)
                            {
                                Player temporary = winners[0];
                                winners[0] = winners[1];
                                winners[1] = temporary;
                            }

                            for (int i = 0; i < winners.Count; i++)
                            {
                                winners[i].Account += winners[i].Contribution;
                            }

                            if (winners[0].Contribution >= losedPlayer.Contribution / 2)
                            {
                                winners[0].Account       += losedPlayer.Contribution / 2;
                                losedPlayer.Contribution -= losedPlayer.Contribution / 2;
                            }
                            else
                            {
                                winners[0].Account       += winners[0].Contribution;
                                losedPlayer.Contribution -= winners[0].Contribution;
                            }

                            if (winners[1].Contribution >= losedPlayer.Contribution)
                            {
                                winners[1].Account      += losedPlayer.Contribution;
                                losedPlayer.Contribution = 0;
                            }
                            else
                            {
                                winners[1].Account       += winners[1].Contribution;
                                losedPlayer.Contribution -= winners[1].Contribution;
                            }

                            losedPlayer.Account += losedPlayer.Contribution;;

                            for (int i = 0; i < winners.Count; i++)
                            {
                                winners[i].ShowRate(this);
                            }
                        }
                        else
                        {
                            foreach (var item in winners)
                            {
                                item.Account += item.Contribution;
                                item.ShowRate(this);
                            }
                        }
                    }

                    else if (winners.Count == 3)
                    {
                        foreach (var item in winners)
                        {
                            item.Account += item.Contribution;
                            item.ShowRate(this);
                        }
                    }

                    foreach (var item in players)
                    {
                        if (item.Account <= 0)
                        {
                            item.IsDefault = true;
                            MessageBox.Show(item.Name + " LOST");
                        }
                        item.AllIn        = false;
                        item.Contribution = 0;
                    }
                }

                foreach (var pl in players)
                {
                    pl.Rate = 0;                       // default rates
                }

                maxRate = 0;

                lblPlAcc.Text = pl1.Account.ToString();
                lblPlAcc.Refresh();
                lblCom1Acc.Text = bot1.Account.ToString();
                lblPlAcc.Refresh();
                lblCom2Acc.Text = bot2.Account.ToString();
                lblPlAcc.Refresh();

                riseIsOccured      = "";
                solutionOfPlayer   = 0;
                indexOfRisedPlayer = -1;

                label2.Text = "";
                label3.Text = "";
                label2.Refresh();
                label3.Refresh();

                sequenceOfGame++;
                Game();
            }
        }
Ejemplo n.º 5
0
        private void riseButton_Click(object sender, EventArgs e)
        {
            int a;

            try
            {
                a = Convert.ToInt32(textBoxRate.Text);
            }
            catch (Exception)
            {
                a = 0;
            }

            for (int i = 0; i < players.Count; i++)
            {
                if (players[i].Name.Equals("Player"))
                {
                    if (a > 0)  // если был райз
                    {
                        riseIsOccured = i.ToString();;
                    }
                    // сделать этого игрока первым в списке торгов
                    break;
                }
            }

            if (pl1.Account + pl1.Rate > a + maxRate)
            {
                pl1.Account -= (maxRate - pl1.Rate) + a;
                maxRate      = maxRate + a;
                pl1.Rate     = maxRate;
            }
            else
            {
                pl1.AllIn   = true;
                pl1.Rate    = pl1.Account + pl1.Rate;
                pl1.Account = 0;
                if (pl1.Rate > maxRate)
                {
                    maxRate = pl1.Rate;
                }
            }

            lblPlRate.Text = pl1.Rate.ToString();
            lblPlRate.Refresh();

            AcceptRateButton.Visible = false;
            AcceptRateButton.Refresh();
            UpRateButton.Visible = false;
            UpRateButton.Refresh();
            DownRateButton.Visible = false;
            DownRateButton.Refresh();
            textBoxRate.Visible = false;
            textBoxRate.Refresh();
            riseButton.Visible = false;
            riseButton.Refresh();
            FallDownButton.Visible = false;
            FallDownButton.Refresh();

            solutionOfPlayer = 1;

            pl1.ShowRate(this);

            Trade();
        }