コード例 #1
0
ファイル: Form1.cs プロジェクト: Tsahi78/New_Battleship
        private void player_mouseclick(object sender, MouseEventArgs e)
        {
            if (flag == 1)
            {
                string[]   separators = { ",", ".", "!", "?", ";", ":", " " };
                PictureBox pb         = (PictureBox)sender;
                int        x          = int.Parse(((string)pb.Tag).Split(separators, StringSplitOptions.RemoveEmptyEntries)[0]);
                int        y          = int.Parse(((string)pb.Tag).Split(separators, StringSplitOptions.RemoveEmptyEntries)[1]);
                Boolean    b          = Horizontal.SelectedIndex == 1 ? true : false;
                Horizontal.Refresh();
                Point[] a;

                Ships ship = null;

                switch (SelectShip.Text)
                {
                case "ship2":

                    a    = ship2.get_point(x, y, b);
                    ship = new ship2(b, a);
                    Console.WriteLine(ship.Name);
                    break;

                case "ship3":
                    a    = ship3.get_point(x, y, b);
                    ship = new ship3(b, a);
                    break;

                case "ship4":
                    a    = ship4.get_point(x, y, b);
                    ship = new ship4(b, a);

                    break;

                case "ship6":
                    a    = ship6.get_point(x, y, b);
                    ship = new ship6(b, a);
                    break;
                }

                if (player.set_ship(ship))
                {
                    player.Ships.Add(ship);

                    SelectShip.Items.RemoveAt(SelectShip.SelectedIndex);
                    SelectShip.SelectedIndex = 0;
                    SelectShip.Refresh();
                    if (SelectShip.Items.Count == 1)
                    {
                        StartButton.Visible = true;
                        SelectShip.Visible  = false;
                        Horizontal.Visible  = false;
                    }
                }


                pic_color_ship(player);
            }
        }