Пример #1
0
        public void Create_Grid(object sender = null, RoutedEventArgs e = null)
        {
            fieldArray = new Field[rows, columns];
            btnArray   = new Button[rows, columns];
            var style = (Style)App.Current.TryFindResource("fieldButton");


            grid.Children.Clear();
            for (int i = 0; i < rows; i++)
            {
                RowDefinition row = new RowDefinition();
                row.Height = GridLength.Auto;
                grid.RowDefinitions.Add(row);


                for (int j = 0; j < columns; j++)
                {
                    ColumnDefinition col = new ColumnDefinition();
                    col.Width = GridLength.Auto;
                    grid.ColumnDefinitions.Add(col);

                    Support.Point pnt = new Support.Point(i, j);

                    Button btn = new Button();
                    btn.CommandParameter            = pnt;
                    btn.Height                      = 1260 / columns;
                    btn.Width                       = 1260 / columns;
                    btn.Style                       = style;
                    btn.Background                  = Brushes.White;
                    btn.PreviewMouseLeftButtonDown += LMB_Down;
                    btn.PreviewMouseLeftButtonUp   += LMB_Up;
                    btn.MouseEnter                 += Put_Wall;
                    btnArray[i, j]                  = btn;

                    Grid.SetColumn(btnArray[i, j], j);
                    Grid.SetRow(btnArray[i, j], i);
                    grid.Children.Add(btnArray[i, j]);


                    fieldArray[i, j] = new Field(i, j);
                }
            }

            foreach (Field field in fieldArray)
            {
                field.Add_Edges(rows, this.columns, fieldArray);
                field.distance = int.MaxValue;
            }
            Set_Start(0, 0);
            Set_Finish(rows - 1, columns - 1);
        }
Пример #2
0
        public void Set_Finish(int row, int col)
        {
            fieldArray[row, col].finish   = true;
            fieldArray[row, col].wall     = false;
            fieldArray[row, col].distance = int.MaxValue;
            finishPoint = new Support.Point(row, col);

            Button threadedBtn = btnArray[row, col];

            threadedBtn.MouseEnter -= Put_Wall;
            threadedBtn.PreviewMouseLeftButtonDown -= LMB_Down;
            threadedBtn.PreviewMouseLeftButtonDown += LMB_Down_Move;
            threadedBtn.Background = Brushes.Coral;
        }
Пример #3
0
        public void Set_Start(int row, int col)
        {
            fieldArray[row, col].start    = true;
            fieldArray[row, col].wall     = false;
            fieldArray[row, col].distance = 0;
            startPoint = new Support.Point(row, col);

            Button threadedBtn = btnArray[row, col];

            threadedBtn.MouseEnter -= Put_Wall;
            threadedBtn.PreviewMouseLeftButtonDown -= LMB_Down;
            threadedBtn.PreviewMouseLeftButtonDown += LMB_Down_Move;
            threadedBtn.Background = Brushes.DodgerBlue;
        }
Пример #4
0
 public void Move_Point(Support.Point pnt)
 {
     if (!vis)
     {
         if (movingStart)
         {
             Set_Empty(startPoint.row, startPoint.col);
             Set_Start(pnt.row, pnt.col);
         }
         else if (movingFinish)
         {
             Set_Empty(finishPoint.row, finishPoint.col);
             Set_Finish(pnt.row, pnt.col);
         }
     }
     movingStart = movingFinish = false;
 }
Пример #5
0
        public void LMB_Down_Move(object sender, MouseButtonEventArgs e)
        {
            Button clicked = (Button)sender;

            Support.Point pnt = (Support.Point)clicked.CommandParameter;

            if (pnt.Is_Equal_To(startPoint))
            {
                movingStart = true;
            }
            else if (pnt.Is_Equal_To(finishPoint))
            {
                movingFinish = true;
            }

            e.Handled = true;
        }
Пример #6
0
        public void Put_Wall(object sender, MouseEventArgs e = null)
        {
            if (mouseDown && !vis)
            {
                Button        clicked = (Button)sender;
                Support.Point pnt     = (Support.Point)clicked.CommandParameter;

                Field  field = fieldArray[pnt.row, pnt.col];
                Button btn   = btnArray[pnt.row, pnt.col];
                if (!field.start && !field.finish)
                {
                    if (field.wall == false)
                    {
                        btn.Background = Brushes.Black;
                        field.wall     = true;
                    }
                    else
                    {
                        btn.Background = Brushes.White;
                        field.wall     = false;
                    }
                }
            }
        }