예제 #1
0
        private void button9_Click(object sender, EventArgs e)
        {
            string name = name_player.Text;



            if (name_player.Text == "")
            {
                MessageBox.Show("u must fill that text ");
            }
            else
            {
                player p = new player();


                counter_of_players--;
                dice d = new dice();

                int a = d.roll_dice();
                int b = d.roll_dice();

                int sum = a + b;



                p.set_name(name);
                p.set_position(sum);
                //
                map.Add(p);
                if (a == 6)
                {
                    panel54.BackgroundImage = Image.FromFile(@"dices\dice(6).png");
                }
                else if (a == 5)
                {
                    panel54.BackgroundImage = Image.FromFile(@"dices\dice(5).png");
                }
                else if (a == 4)
                {
                    panel54.BackgroundImage = Image.FromFile(@"dices\dice(4).png");
                }
                else if (a == 3)
                {
                    panel54.BackgroundImage = Image.FromFile(@"dices\dice(3).png");
                }
                else if (a == 2)
                {
                    panel54.BackgroundImage = Image.FromFile(@"dices\dice(2).png");
                }
                else if (a == 1)
                {
                    panel54.BackgroundImage = Image.FromFile(@"dices\dice(1).png");
                }


                if (b == 6)
                {
                    panel55.BackgroundImage = Image.FromFile(@"dices\dice(6).png");
                }
                else if (b == 5)
                {
                    panel55.BackgroundImage = Image.FromFile(@"dices\dice(5).png");
                }
                else if (b == 4)
                {
                    panel55.BackgroundImage = Image.FromFile(@"dices\dice(4).png");
                }
                else if (b == 3)
                {
                    panel55.BackgroundImage = Image.FromFile(@"dices\dice(3).png");
                }
                else if (b == 2)
                {
                    panel55.BackgroundImage = Image.FromFile(@"dices\dice(2).png");
                }
                else if (b == 1)
                {
                    panel55.BackgroundImage = Image.FromFile(@"dices\dice(1).png");
                }
                view_list = new ListViewItem(name_player.Text);
                view_list.SubItems.Add(sum.ToString());

                listView1.Items.Add(view_list);
            }

            name_player.Text = "";



            if (counter_of_players == 0)
            {
                map.Sort();
                for (int i = 0; i < map.Count; i++)
                {
                    map[i].set_position(0);
                    map[i].set_money(1200);
                    map[i].set_first_time_to_roll_done(false);
                    map[i].set_In_jail_now(false);
                    map[i].set_Was_in_jail(false);
                }
                game.first_initialize(map);
                if (map.Count == 2)
                {
                    pictureBox1.Location = new Point(x, y);
                    pictureBox2.Location = new Point(x, y);
                    pictureBox3.Visible  = false;
                    pictureBox4.Visible  = false;
                    pictureBox5.Visible  = false;
                    pictureBox6.Visible  = false;
                    pictureBox7.Visible  = false;
                    pictureBox8.Visible  = false;
                }
                else if (map.Count == 3)
                {
                    pictureBox1.Location = new Point(x, y);
                    pictureBox2.Location = new Point(x, y);
                    pictureBox3.Location = new Point(x, y);
                    pictureBox4.Visible  = false;
                    pictureBox5.Visible  = false;
                    pictureBox6.Visible  = false;
                    pictureBox7.Visible  = false;
                    pictureBox8.Visible  = false;
                }
                else if (map.Count == 4)
                {
                    pictureBox1.Location = new Point(x, y);
                    pictureBox2.Location = new Point(x, y);
                    pictureBox3.Location = new Point(x, y);
                    pictureBox4.Location = new Point(x, y);
                    pictureBox5.Visible  = false;
                    pictureBox6.Visible  = false;
                    pictureBox7.Visible  = false;
                    pictureBox8.Visible  = false;
                }
                else if (map.Count == 5)
                {
                    pictureBox1.Location = new Point(x, y);
                    pictureBox2.Location = new Point(x, y);
                    pictureBox3.Location = new Point(x, y);
                    pictureBox4.Location = new Point(x, y);
                    pictureBox5.Location = new Point(x, y);
                    pictureBox6.Visible  = false;
                    pictureBox7.Visible  = false;
                    pictureBox8.Visible  = false;
                }
                else if (map.Count == 6)
                {
                    pictureBox1.Location = new Point(x, y);
                    pictureBox2.Location = new Point(x, y);
                    pictureBox3.Location = new Point(x, y);
                    pictureBox4.Location = new Point(x, y);
                    pictureBox5.Location = new Point(x, y);
                    pictureBox6.Location = new Point(x, y);
                    pictureBox7.Visible  = false;
                    pictureBox8.Visible  = false;
                }
                else if (map.Count == 7)
                {
                    pictureBox1.Location = new Point(x, y);
                    pictureBox2.Location = new Point(x, y);
                    pictureBox3.Location = new Point(x, y);
                    pictureBox4.Location = new Point(x, y);
                    pictureBox5.Location = new Point(x, y);
                    pictureBox6.Location = new Point(x, y);
                    pictureBox7.Location = new Point(x, y);
                    pictureBox8.Visible  = false;
                }
                else if (map.Count == 8)
                {
                    pictureBox1.Location = new Point(x, y);
                    pictureBox2.Location = new Point(x, y);
                    pictureBox3.Location = new Point(x, y);
                    pictureBox4.Location = new Point(x, y);
                    pictureBox5.Location = new Point(x, y);
                    pictureBox6.Location = new Point(x, y);
                    pictureBox7.Location = new Point(x, y);
                    pictureBox8.Location = new Point(x, y);
                }
                button10.Visible    = true;
                label22.Visible     = false;
                name_player.Visible = false;
                button9.Visible     = false;
                panel54.Visible     = false;
                panel55.Visible     = false;
            }
        }
예제 #2
0
 public void SendToJail(ref player obj)
 {
     obj.set_position(9);
 }
예제 #3
0
        // static Random s = new Random();//static make good randomisation
        private void button4_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            btn_roll_dice.Enabled = false;
            btn_end_turn.Enabled  = true;

            play = game.get_player_at_index(game.get_index());

            first_dice = play.get_rolld_dice();
            //game.get_list_country()[play.get_position()].propertize(3, ref panel1, 0, ref play, ref game);
            second_dice = play.get_rolld_dice();



            //


            if ((play.get_position() + first_dice + second_dice) >= 36 && play.get_first_time_to_roll_done() == false)
            {
                btn_leave.Enabled = true;
                play.set_first_time_to_roll_done(true);
                if (play.get_Was_in_jail() == false)
                {
                    play.set_money(play.get_money() + 200);
                    MessageBox.Show("you have earned 200$.");
                }
                else if (play.get_Was_in_jail() == true)
                {
                    play.set_Was_in_jail(false);
                }
            }
            else if ((play.get_position() + first_dice + second_dice) >= 36 && play.get_first_time_to_roll_done() == true)
            {
                if (play.get_Was_in_jail() == false)
                {
                    play.set_money(play.get_money() + 200);
                    MessageBox.Show("you have earned 200$.");
                }
                else if (play.get_Was_in_jail() == true)
                {
                    play.set_Was_in_jail(false);
                }
            }
            if (play.get_In_jail_now() == true)
            {
                if (second_dice == first_dice)
                {
                    game.jail.Checker_double_get_out_from_jail(ref play, true, first_dice + second_dice);
                }
                else
                {
                    game.jail.Checker_double_get_out_from_jail(ref play, false, first_dice + second_dice);
                }
            }
            if (play.get_In_jail_now() == false)
            {
                if (second_dice == first_dice)
                {
                    if (play.add_double_list_to_go_to_jail(true) == true)
                    {
                        game.jail.set_prisoners_with_going_jail(ref play);
                        MessageBox.Show("you will send to jail As you played three doubles. ");
                    }
                }
                else
                {
                    play.add_double_list_to_go_to_jail(false);
                }
            }
            if (play.get_In_jail_now() == false)
            {
                play.set_position((play.get_position() + first_dice + second_dice) % 36);
            }
            btn_leave.Visible = true;
            //country


            if ((game.get_list_country()[play.get_position()]).GetType() == typeof(Jail))
            {
                if (play.get_In_jail_now() == false)
                {
                    listBox1.Items.Add("you are in jail  ");
                    //game.get_list_country()[play.get_position()].propertize(3, ref panel1, 0, ref play, ref game);

                    // game.jail.set_prisoners_with_going_jail(ref play);
                    btn_sell_hotel.Enabled = true;
                    btn_sell_land.Enabled  = true;
                    btn_leave.Enabled      = true;
                    btn_end_turn.Enabled   = true;
                }
            }
            else if ((game.get_list_country()[play.get_position()]).GetType() == typeof(station))
            {
                game.get_list_country()[play.get_position()].propertize(3, ref panel1, 0, ref play, ref game);
                btn_sell_hotel.Enabled = true;
                btn_sell_land.Enabled  = true;
                btn_leave.Enabled      = true;
                btn_end_turn.Enabled   = true;
            }
            else if ((game.get_list_country()[play.get_position()]).GetType() == typeof(income_tax))
            {
                game.get_list_country()[play.get_position()].propertize(3, ref panel1, 0, ref play, ref game);
                btn_sell_hotel.Enabled = true;
                btn_sell_land.Enabled  = true;
                btn_leave.Enabled      = true;
                btn_end_turn.Enabled   = true;
            }
            else if ((game.get_list_country()[play.get_position()]).GetType() == typeof(water_works))
            {
                game.get_list_country()[play.get_position()].propertize(3, ref panel1, 0, ref play, ref game);
                btn_sell_hotel.Enabled = true;
                btn_sell_land.Enabled  = true;
                btn_leave.Enabled      = true;
                btn_end_turn.Enabled   = true;
            }
            else if ((game.get_list_country()[play.get_position()]).GetType() == typeof(go_token))
            {
                game.get_list_country()[play.get_position()].propertize(3, ref panel1, 0, ref play, ref game);
                btn_sell_hotel.Enabled = true;
                btn_sell_land.Enabled  = true;
                btn_leave.Enabled      = true;
                btn_end_turn.Enabled   = true;
            }
            else if ((game.get_list_country()[play.get_position()]).GetType() == typeof(GoToJail))
            {
                //game.get_list_country()[play.get_position()].propertize(3, ref panel1, 0, ref play, ref game);
                game.jail.set_prisoners_with_going_jail(ref play);

                MessageBox.Show(" you will go to jail by go to jail token. ");
                btn_sell_hotel.Enabled = true;
                btn_sell_land.Enabled  = true;
                btn_leave.Enabled      = true;
                btn_end_turn.Enabled   = true;
            }
            else if ((game.get_list_country()[play.get_position()]).GetType() == typeof(community_chest))
            {
                int pic2 = R.Next(1, 7);
                game.get_list_country()[play.get_position()].propertize(3, ref panel53, pic2, ref play, ref game);
                btn_sell_hotel.Enabled = true;
                btn_sell_land.Enabled  = true;
                btn_leave.Enabled      = true;
                btn_end_turn.Enabled   = true;
                panel53.Visible        = true;
            }

            else if ((game.get_list_country()[play.get_position()]).GetType() == typeof(chance))
            {
                int pic2 = R.Next(1, 7);
                game.get_list_country()[play.get_position()].propertize(3, ref panel53, pic2, ref play, ref game);
                btn_sell_hotel.Enabled = true;
                btn_sell_land.Enabled  = true;
                btn_leave.Enabled      = true;
                btn_end_turn.Enabled   = true;
                panel53.Visible        = true;
            }
            else if ((game.get_list_country()[play.get_position()]).GetType() == typeof(electric_company))
            {
                game.get_list_country()[play.get_position()].propertize(3, ref panel1, 0, ref play, ref game);
                btn_sell_hotel.Enabled = true;
                btn_sell_land.Enabled  = true;
                btn_leave.Enabled      = true;
                btn_end_turn.Enabled   = true;
            }
            else if ((game.get_list_country()[play.get_position()]).GetType() == typeof(Super_tax))
            {
                game.get_list_country()[play.get_position()].propertize(3, ref panel1, 0, ref play, ref game);
                btn_sell_hotel.Enabled = true;
                btn_sell_land.Enabled  = true;
                btn_leave.Enabled      = true;
                btn_end_turn.Enabled   = true;
            }
            listBox1.Items.Add("Player Name:     " + play.get_name());
            listBox1.Items.Add("Player Money:    " + play.get_money());
            listBox1.Items.Add("Player Country:  ");
            if (play.get_countrylist().Count == 0)
            {
                listBox1.Items.Add("You dont have countries.");
            }
            for (int i = 0; i < play.get_countrylist().Count; i++)
            {
                listBox1.Items.Add("you have " + play.get_countrylist()[i].get_name() + "and it`s price is " + play.get_countrylist()[i].get_cost() + "$.");
                if (play.get_countrylist()[i].get_build_hotel() == true)
                {
                    listBox1.Items.Add("you have an hotel on this country and its price " + play.get_countrylist()[i].get_over_cost());
                }
            }
            if ((game.get_list_country()[play.get_position()]).GetType() == typeof(country))
            {    //this player is owner
                listBox1.Items.Add("..................................................");
                listBox1.Items.Add("this token is called  " + game.get_country_with_pos(play.get_position()).get_name());
                listBox1.Items.Add("It costs  " + game.get_country_with_pos(play.get_position()).get_cost() + "    and its rent =" + game.get_country_with_pos(play.get_position()).get_rent());
                listBox1.Items.Add("The hotel costs " + game.get_country_with_pos(play.get_position()).get_over_cost() + "    and its hotel rent =" + game.get_country_with_pos(play.get_position()).get_over_rent());
            }
            if (play.get_first_time_to_roll_done() == true && (game.get_list_country()[play.get_position()]).GetType() == typeof(country))
            {
                //this player is owner
                //  MessageBox.Show("hahahaahah");
                btn_sell_hotel.Enabled = true;
                btn_sell_land.Enabled  = true;
                if (play.check_if_this_player_is_owener_of_this_country(game.get_country_with_pos(play.get_position())) == true)
                {
                    //  MessageBox.Show("0000000000000000000");

                    btn_rent.Enabled = false;
                    //check_if_player_owner_of_the_group
                    if (play.check_if_player_owner_of_the_group(game.get_list_group(), (game.get_country_with_pos(play.get_position()))) == true)
                    {
                        if (game.get_country_with_pos(play.get_position()).get_build_hotel() == false)
                        {
                            btn_buy_hotel.Enabled = true;
                        }
                    }
                }
                else
                {        //rent
                    if (game.get_country_with_pos(play.get_position()).get_available() == false)
                    {
                        btn_buy_land.Enabled = true;
                    }
                    else
                    {
                        btn_sell_hotel.Enabled = true;
                        btn_sell_land.Enabled  = true;
                        btn_rent.Enabled       = true;
                        btn_end_turn.Enabled   = false;
                        btn_buy_hotel.Enabled  = false;
                        btn_buy_land.Enabled   = false;
                    }
                }
            }
            //check if the player is the owner of this coutry

            /*  (n == 1)//PLAYER is the owner of country &you want sell land
             * (n == 2)//PLAYER is the owner of country &you want sell hotel
             * (n == 3)//PLAYER is Not the owner of country &you want buy land
             * (n == 4)//PLAYER is Not the owner of country &you want buy hotel*/



            //loading dice pictures//////////


            if (first_dice == 6)
            {
                pic_dice_1.BackgroundImage = Image.FromFile(@"dices\dice(6).png");
            }
            if (first_dice == 5)
            {
                pic_dice_1.BackgroundImage = Image.FromFile(@"dices\dice(5).png");
            }
            if (first_dice == 4)
            {
                pic_dice_1.BackgroundImage = Image.FromFile(@"dices\dice(4).png");
            }
            if (first_dice == 3)
            {
                pic_dice_1.BackgroundImage = Image.FromFile(@"dices\dice(3).png");
            }
            if (first_dice == 2)
            {
                pic_dice_1.BackgroundImage = Image.FromFile(@"dices\dice(2).png");
            }
            if (first_dice == 1)
            {
                pic_dice_1.BackgroundImage = Image.FromFile(@"dices\dice(1).png");
            }
            if (second_dice == 6)
            {
                pic_dice_2.BackgroundImage = Image.FromFile(@"dices\dice(6).png");
            }
            if (second_dice == 5)
            {
                pic_dice_2.BackgroundImage = Image.FromFile(@"dices\dice(5).png");
            }
            if (second_dice == 4)
            {
                pic_dice_2.BackgroundImage = Image.FromFile(@"dices\dice(4).png");
            }
            if (second_dice == 3)
            {
                pic_dice_2.BackgroundImage = Image.FromFile(@"dices\dice(3).png");
            }
            if (second_dice == 2)
            {
                pic_dice_2.BackgroundImage = Image.FromFile(@"dices\dice(2).png");
            }
            if (second_dice == 1)
            {
                pic_dice_2.BackgroundImage = Image.FromFile(@"dices\dice(1).png");
            }


            if (game.get_index() == 0)
            {
                pictureBox1.Location = new Point(location_country[play.get_position()].Item1, location_country[play.get_position()].Item2);
            }
            else if (game.get_index() == 1)
            {
                pictureBox2.Location = new Point(location_country[play.get_position()].Item1, location_country[play.get_position()].Item2);
            }
            else if (game.get_index() == 2)
            {
                pictureBox3.Location = new Point(location_country[play.get_position()].Item1, location_country[play.get_position()].Item2);
            }
            else if (game.get_index() == 3)
            {
                pictureBox4.Location = new Point(location_country[play.get_position()].Item1, location_country[play.get_position()].Item2);
            }
            else if (game.get_index() == 4)
            {
                pictureBox5.Location = new Point(location_country[play.get_position()].Item1, location_country[play.get_position()].Item2);
            }
            else if (game.get_index() == 5)
            {
                pictureBox6.Location = new Point(location_country[play.get_position()].Item1, location_country[play.get_position()].Item2);
            }
            else if (game.get_index() == 6)
            {
                pictureBox7.Location = new Point(location_country[play.get_position()].Item1, location_country[play.get_position()].Item2);
            }
            else if (game.get_index() == 7)
            {
                pictureBox8.Location = new Point(location_country[play.get_position()].Item1, location_country[play.get_position()].Item2);
            }
        }