Beispiel #1
0
        //Нажатие
        private void B_Click(object sender, EventArgs e)
        {
            try
            {
                CellButton b = (CellButton)sender;
                if (!game.My.CheckAround(b.X, b.Y))
                {
                    return;
                }
                switch (cells)
                {
                //1 button ship
                case 1:
                    b.BackColor   = Color.LightSkyBlue;
                    ship1.Checked = false;
                    game.My.Addship1(b.X, b.Y);
                    //возврат в осн режим
                    cells = 0;
                    break;

                //2 button ship
                case 2:
                    if (cell == null)
                    {
                        //1st button
                        b.BackColor = Color.OrangeRed;
                        cell        = new Data.Cell(b.X, b.Y);
                    }
                    else if (!cell.CheckNear(b.X, b.Y))
                    {
                        //wrong button pressed
                        return;
                    }
                    else
                    {
                        //colour 1st button
                        getButton(cell.X, cell.Y).BackColor = Color.Orange;
                        //colour 2st button
                        b.BackColor = Color.OrangeRed;
                        //release button
                        ship2.Checked = false;
                        // add 2button ship
                        game.My.Addship2(cell, b.X, b.Y);
                        //erease marked button
                        cell = null;
                        //возврат в осн режим
                        cells = 0;
                    }
                    break;
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "Печаль");
            }
        }
Beispiel #2
0
 //Обработка событий формы
 private void Form1_Load(object sender, EventArgs e)
 {
     for (int x = 0; x < 10; x++)
     {
         for (int y = 0; y < 10; y++)
         {
             //creation button
             var b = new CellButton(x, y);
             b.Name = string.Format("{0,2}{1,2}", x, y);
             b.Size = new Size(32, 32);
             //+hight of toolbox
             b.Location = new Point(40 * x, 40 * y + menu.Height + tool.Height);
             b.Click   += B_Click;;
             //add button to form
             Controls.Add(b);
         }
     }
 }
Beispiel #3
0
 private CellButton getButton(int x, int y)
 {
     foreach (Control control in Controls)
     {
         //check cast type
         if (!(control is CellButton))
         {
             continue;
         }
         // cast type
         CellButton button = (CellButton)control;
         //check same button
         if ((button.X == x) && (button.Y == y))
         {//founded right button
             return(button);
         }
     }
     return(null);
 }