Exemple #1
0
        //при нажатии на ячейку
        private void dgvLabirinth_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            //если маршрут был построен, стираем его
            if (routeIsBuilt)
            {
                DataGridViewUtils.ClearWay(dgvLabirinth);//красные->стены, зеленые->проход
                routeIsBuilt = false;
            }

            var cell = dgvLabirinth[e.ColumnIndex, e.RowIndex];

            //получаем цвет текущей ячейки
            Color color = cell.Style.BackColor;

            //не допускаем нажатия нескольких checkBox'ов
            if (checkedEdit.CheckedItems.Count > 0)
            {
                switch (checkedEdit.SelectedIndex)
                {
                //стена
                case 0:
                    color = Color.Black;
                    break;

                //вход
                case 1:
                    color = Color.Blue;
                    //если отметка уже была, стираем старую
                    if (start.X != -1)
                    {
                        dgvLabirinth[start.X, start.Y].Style.BackColor = Color.White;
                    }
                    start = new Point(cell.ColumnIndex, cell.RowIndex);
                    break;

                //выход
                case 2:
                    color = Color.DarkBlue;
                    if (finish.X != -1)
                    {
                        dgvLabirinth[finish.X, finish.Y].Style.BackColor = Color.White;
                    }
                    finish = new Point(cell.ColumnIndex, cell.RowIndex);
                    break;
                }

                //если в ней было пусто
                if (cell.Style.BackColor == Color.White)
                {
                    cell.Style.BackColor = color;
                }
                else
                {
                    cell.Style.BackColor = Color.White;
                }
            }

            //убираем цвет выбора
            cell.Style.SelectionBackColor = cell.Style.BackColor;
        }
Exemple #2
0
 //найти путь
 private void btnRun_Click(object sender, EventArgs e)
 {
     if (!DataGridViewUtils.CheckDataGridView(dgvLabirinth))
     {
         MessageBox.Show("В лабиринте должен быть один вход и один выход.",
                         "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         routeIsBuilt = lbr.FindWay((int)countGrenades.Value, (int)size.Value, start, finish);
         //countGrenades и size - с формы
     }
 }
Exemple #3
0
 private void btnClear_Click(object sender, EventArgs e)
 {
     dgvLabirinth.ClearSelection();
     DataGridViewUtils.Clear(dgvLabirinth);
 }
Exemple #4
0
 //создание рандомного лабиринта
 private void btnRandom_Click(object sender, EventArgs e)
 {
     DataGridViewUtils.RandomDataGridView(dgvLabirinth, rnd, ref start, ref finish);
 }
 //конструктор лабиринта
 public Labirinth(DataGridView dgv, int size)
 {
     this.dgv = dgv;
     DataGridViewUtils.ShowDataGridView(dgv, size);
 }