コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap   buff = new Bitmap("monopoly.jpg");
            Graphics a    = Graphics.FromImage(buff);

            pictureBox1.Image = buff;
            p1.TakeTurn(piece1);
            p2.board.owned = p1.board.owned;
            p2.Money      += p1.GivenMoney;
            p1.GivenMoney  = 0;
            imageList1.Draw(a, new Point(piece1.X, piece1.Y), 0);

            foreach (Square p in p1.PlayersStreets)
            {
                textBox1.AppendText(p.name + "    ");
            }
            foreach (Square p in p2.PlayersStreets)
            {
                textBox2.AppendText(p.name + "    ");
            }
            p1.added = null;
            if (p1.Money < 0 && p1.PlayersStreets.Count != 0)
            {
                //начать продавать
                while (p1.Money <= 0 || p1.PlayersStreets.Count != 0)
                {
                    p1.board.owned.Remove(p1.PlayersStreets.Peek().sell);
                    if (p2.AbleToSpend(p1.PlayersStreets.Peek().Cost / 2))
                    {
                        p2.own.Add(p1.PlayersStreets.Peek().sell);
                        p2.PlayersStreets.Enqueue(p1.PlayersStreets.Peek());
                        p2.Spend(p1.PlayersStreets.Peek().Cost / 2);
                        p2.board.owned.Add(p1.PlayersStreets.Peek().sell);
                    }
                    p1.Gain(p1.PlayersStreets.Peek().Cost / 2);
                    p1.own.Remove(p1.PlayersStreets.Peek().sell);
                    textBox3.Text = p1.PlayersStreets.Dequeue().name;
                }
            }
            if (p1.Money < 0 && p1.PlayersStreets == null)
            {
                Hide();
                Form3 form3 = new Form3();
                form3.ShowDialog();
                Close();
            }
            p2.TakeTurn(piece2);
            p1.Money      += p2.GivenMoney;
            p2.GivenMoney  = 0;
            p1.board.owned = p2.board.owned;
            imageList1.Draw(a, new Point(piece2.X, piece2.Y), 1);
            label6.Text = "Переход на " + p1.diceValue.ToString() + "  Остаток: " + p1.Money.ToString() + " $";

            label7.Text = "Переход на " + p2.diceValue.ToString() + "  Остаток: " + p2.Money.ToString() + " $";
            p2.added    = null;
            if (p2.Money < 0 && p2.PlayersStreets.Count != 0)
            {
                while (p2.Money <= 0 || p2.PlayersStreets.Count != 0)
                {
                    p2.board.owned.Remove(p1.PlayersStreets.Peek().sell);
                    if (p1.AbleToSpend(p2.PlayersStreets.Peek().Cost / 2))
                    {
                        p2.own.Add(p1.PlayersStreets.Peek().sell);
                        p2.PlayersStreets.Enqueue(p1.PlayersStreets.Peek());
                        p1.Spend(p1.PlayersStreets.Peek().Cost / 2);
                    }
                    p2.Gain(p1.PlayersStreets.Peek().Cost / 2);
                    p1.own.Remove(p1.PlayersStreets.Peek().sell);
                    textBox3.Text = p2.PlayersStreets.Dequeue().name;
                }
            }
            if (p2.Money < 0 && p2.PlayersStreets == null)
            {
                Hide();
                Form4 form4 = new Form4();
                form4.ShowDialog();
                Close();     // Открытие новой формы
            }
            textBox1.Clear();
            textBox2.Clear();
        }
コード例 #2
0
ファイル: Players.cs プロジェクト: OlegGolovanovHW/Monopoly
        public void Move(Label balance_capital, Label DicesValue, PictureBox[] cells_list, Panel[] firms_owners_list, Label[] firms_costs_list, PictureBox picture, ListBox list_box, Button current_button, Button next_button, Form1 main_form)
        {
            List <PictureBox> cells        = new List <PictureBox>(cells_list);
            List <Panel>      firms_owners = new List <Panel>(firms_owners_list);
            List <Label>      firms_costs  = new List <Label>(firms_costs_list);

            this.Balance        += this.CurrentProfit;
            this.Capital        += this.CurrentProfit;
            balance_capital.Text = this.Balance.ToString() + " | " + this.Capital.ToString() + " | " + this.CurrentProfit.ToString();
            if (!this.DiceThrown)
            {
                int first  = Game.Dices.GenerateFirstValue();
                int second = Game.Dices.GenerateSecondValue();
                if (this.CurrentPosition + first + second > cells.Count - 1)
                {
                    //прошли через "start"
                    this.CurrentPosition = this.CurrentPosition + first + second - cells.Count;
                    this.Balance        += 200;
                    this.Capital        += 200;
                    balance_capital.Text = this.Balance.ToString() + " | " + this.Capital.ToString() + " | " + this.CurrentProfit.ToString();
                }
                else
                {
                    this.CurrentPosition += first + second;
                }
                DicesValue.Text     = "Кости: " + first.ToString() + " + " + second.ToString();
                this.DiceThrown     = true; //бросили кости
                next_button.Enabled = true;
                if (this is Artificial_Intelligence)
                {
                    current_button.Enabled   = false;
                    current_button.BackColor = Color.Gray;
                    next_button.BackColor    = Color.LimeGreen;
                    next_button.Text         = "Бросить кости";
                }
                string tag_num = "";
                string tag_own = "";
                foreach (var item in cells)
                {
                    tag_num = "";
                    tag_own = item.Tag.ToString()[item.Tag.ToString().Length - 1].ToString();
                    for (int i = 0; i < item.Tag.ToString().Length - 1; i++)
                    {
                        tag_num += item.Tag.ToString()[i]; //отсекаем часть, отвечающую за принадлежность территории
                    }
                    if (tag_num.Equals(this.CurrentPosition.ToString()))
                    {
                        if (this is Person)
                        {
                            picture.Location = new Point(item.Location.X, item.Location.Y);
                        }
                        if (this is Artificial_Intelligence)
                        {
                            picture.Location = new Point(item.Location.X - 5, item.Location.Y);
                        }
                        this.NameOfCurrentCard = item.Name;
                        break;
                    }
                }
                //если территория - фирма, и если она не принадлежит другому, предложить купить (if Player is Person)
                if (Game.CostOfFirms.ContainsKey(this.NameOfCurrentCard))
                {
                    if (tag_own == "N")
                    {
                        if (this is Person) //если Person, то предлагаем приобрести фирму
                        {
                            current_button.Text          = "Приобрести фирму?";
                            main_form.plusFilial.Enabled = false;
                            main_form.Sell.Enabled       = false;
                        }
                        if (this is Artificial_Intelligence) //если AI, то приобретаем фирму, если возможно, и если AI не совершит другого(!)
                        {
                            this.BuySomething(balance_capital, cells, firms_owners, firms_costs, list_box, current_button, next_button, main_form);
                        }
                    }
                    else if (tag_own == "B")
                    {
                        if (this is Person)
                        {
                            foreach (var buf in main_form.listBoxBlue.Items)
                            {
                                if (buf.ToString() == "- " + this.NameOfCurrentCard + " x1")
                                {
                                    this.Balance -= RentFee[this.NameOfCurrentCard].rent * 1;
                                    this.Capital -= RentFee[this.NameOfCurrentCard].rent * 1;
                                    break;
                                }
                                else if (buf.ToString() == "- " + this.NameOfCurrentCard + " x2")
                                {
                                    this.Balance -= RentFee[this.NameOfCurrentCard].rent * 2;
                                    this.Capital -= RentFee[this.NameOfCurrentCard].rent * 2;
                                    break;
                                }
                                else if (buf.ToString() == "- " + this.NameOfCurrentCard + " x3")
                                {
                                    this.Balance -= RentFee[this.NameOfCurrentCard].rent * 3;
                                    this.Capital -= RentFee[this.NameOfCurrentCard].rent * 3;
                                    break;
                                }
                                else if (buf.ToString() == "- " + this.NameOfCurrentCard + " x4")
                                {
                                    this.Balance -= RentFee[this.NameOfCurrentCard].rent * 4;
                                    this.Capital -= RentFee[this.NameOfCurrentCard].rent * 4;
                                    break;
                                }
                                else if (buf.ToString() == "- " + this.NameOfCurrentCard + " x5")
                                {
                                    this.Balance -= DoubleRentFee[this.NameOfCurrentCard].rent;
                                    this.Capital -= DoubleRentFee[this.NameOfCurrentCard].rent;
                                    break;
                                }
                            }
                            balance_capital.Text         = this.Balance.ToString() + " | " + this.Capital.ToString() + " | " + this.CurrentProfit.ToString();
                            current_button.Text          = "Бросить кости";
                            current_button.Enabled       = false;
                            current_button.BackColor     = Color.Gray;
                            next_button.Enabled          = true;
                            next_button.BackColor        = Color.LimeGreen;
                            main_form.plusFilial.Enabled = false;
                            main_form.Sell.Enabled       = false;
                        }
                        if (this is Artificial_Intelligence)
                        {
                            //AI может(даже делает) приобрести филиал
                            //логика приобретения филиала AI
                            this.BuySomething(balance_capital, cells, firms_owners, firms_costs, list_box, current_button, next_button, main_form);
                        }
                    }
                    else if (tag_own == "R")
                    {
                        if (this is Person)
                        {
                            //предложить приобрести филиал
                            //CanBuyFilial == true
                            //логика приобретения филиала Person
                            main_form.plusFilial.Enabled = true;
                            main_form.Sell.Enabled       = true;
                        }
                        if (this is Artificial_Intelligence) //заплатить налоги
                        {
                            foreach (var buf in main_form.listBoxRed.Items)
                            {
                                if (buf.ToString() == "- " + this.NameOfCurrentCard + " x1")
                                {
                                    this.Balance -= RentFee[this.NameOfCurrentCard].rent * 1;
                                    this.Capital -= RentFee[this.NameOfCurrentCard].rent * 1;
                                    break;
                                }
                                else if (buf.ToString() == "- " + this.NameOfCurrentCard + " x2")
                                {
                                    this.Balance -= RentFee[this.NameOfCurrentCard].rent * 2;
                                    this.Capital -= RentFee[this.NameOfCurrentCard].rent * 2;
                                    break;
                                }
                                else if (buf.ToString() == "- " + this.NameOfCurrentCard + " x3")
                                {
                                    this.Balance -= RentFee[this.NameOfCurrentCard].rent * 3;
                                    this.Capital -= RentFee[this.NameOfCurrentCard].rent * 3;
                                    break;
                                }
                                else if (buf.ToString() == "- " + this.NameOfCurrentCard + " x4")
                                {
                                    this.Balance -= RentFee[this.NameOfCurrentCard].rent * 4;
                                    this.Capital -= RentFee[this.NameOfCurrentCard].rent * 4;
                                    break;
                                }
                                else if (buf.ToString() == "- " + this.NameOfCurrentCard + " x5")
                                {
                                    this.Balance -= DoubleRentFee[this.NameOfCurrentCard].rent;
                                    this.Capital -= DoubleRentFee[this.NameOfCurrentCard].rent;
                                    break;
                                }
                            }
                            balance_capital.Text = this.Balance.ToString() + " | " + this.Capital.ToString() + " | " + this.CurrentProfit.ToString();
                        }
                    }
                }
                //если попали на лотерею
                else if (this.NameOfCurrentCard == "lottery_left" || this.NameOfCurrentCard == "lottery_right" || this.NameOfCurrentCard == "lottery_top" || this.NameOfCurrentCard == "lottery_bottom")
                {
                    current_button.Enabled   = false;
                    current_button.BackColor = Color.Gray;
                    next_button.Enabled      = true;
                    next_button.BackColor    = Color.LimeGreen;
                    string s_buf = Lottery.GetPrize();
                    if (this is Person)
                    {
                        main_form.plusFilial.Enabled = false;
                        main_form.Sell.Enabled       = false;
                        Form2 info = new Monopoly.Form2();
                        info.info.Text = s_buf;
                        info.Show();
                    }
                    this.Balance        += Lottery.Prize;
                    this.Capital        += Lottery.Prize;
                    balance_capital.Text = this.Balance.ToString() + " | " + this.Capital.ToString() + " | " + this.CurrentProfit.ToString();
                }
                //если попали на "шанс"
                else if (this.NameOfCurrentCard == "chance_left" || this.NameOfCurrentCard == "chance_right" || this.NameOfCurrentCard == "chance_top" || this.NameOfCurrentCard == "chance_bottom")
                {
                    current_button.Enabled   = false;
                    current_button.BackColor = Color.Gray;
                    next_button.Enabled      = true;
                    next_button.BackColor    = Color.LimeGreen;
                    string s_buf = Chance.GetChance();
                    if (this is Person)
                    {
                        main_form.plusFilial.Enabled = false;
                        main_form.Sell.Enabled       = false;
                        Form2 info = new Monopoly.Form2();
                        info.info.Text = s_buf;
                        info.Show();
                    }
                    this.Balance += Chance.Prize;
                    this.Capital += Chance.Prize;
                    if (Chance.FreeOutFromPrison == true)
                    {
                        this.FreeOutFromPrison++;
                    }
                    balance_capital.Text = this.Balance.ToString() + " | " + this.Capital.ToString() + " | " + this.CurrentProfit.ToString();
                }
                //если попали в тюрьму
                else if (this.NameOfCurrentCard == "prison_cell_left_top" || this.NameOfCurrentCard == "prison_cell_right_bottom")
                {
                    main_form.plusFilial.Enabled = false;
                    main_form.Sell.Enabled       = false;
                    current_button.Enabled       = false;
                    current_button.BackColor     = Color.Gray;
                    next_button.Enabled          = true;
                    next_button.BackColor        = Color.LimeGreen;
                    this.InPrison           = true;
                    this.prison.MovesToWait = 3;
                    if (this is Person)
                    {
                        Form4 prison = new Form4(balance_capital, DicesValue, cells_list, firms_owners_list, firms_costs_list, picture, list_box, current_button, next_button, ref main_form);
                        prison.Show();
                        main_form.Enabled = false;
                    }
                }
                //если попали на "next"
                else if (this.NameOfCurrentCard == "next_cell")
                {
                    main_form.plusFilial.Enabled = false;
                    main_form.Sell.Enabled       = false;
                    current_button.Enabled       = false;
                    current_button.BackColor     = Color.Gray;
                    next_button.Enabled          = true;
                    next_button.BackColor        = Color.LimeGreen;
                    this.Balance        += 400;
                    this.Capital        += 400;
                    balance_capital.Text = this.Balance.ToString() + " | " + this.Capital.ToString() + " | " + this.CurrentProfit.ToString();
                }
            }
            else
            {
                if (current_button.Text == "Приобрести фирму?") //приобретаем фирму
                {
                    this.BuySomething(balance_capital, cells, firms_owners, firms_costs, list_box, current_button, next_button, main_form);
                }
            }
            //if (this.prison.MovesToWaitEnemy > 0) this.prison.MovesToWaitEnemy--;
        }