Пример #1
0
 private void Draw()
 {
     for (int col = 0; col < _game.Size; col++)
     {
         for (int row = 0; row < _game.Size; row++)
         {
             MyRectangle rect;
             rect   = new MyRectangle();
             rect.X = col;
             rect.Y = row;
             rect.Rectangle.Fill = _game.ValueOfPoint(col, row) == 1
                 ? new SolidColorBrush(Colors.Black)
                 : new SolidColorBrush(Colors.White);
             rect.Rectangle.Width  = Width / _game.Size;
             rect.Rectangle.Height = Height / _game.Size;
             rect.Rectangle.Stroke = new SolidColorBrush(Colors.Green);
             Canvas.SetLeft(rect.Rectangle, col * 30);
             Canvas.SetTop(rect.Rectangle, row * 30);
             rect.Rectangle.MouseDown += (s, e) => RectOnMouseDown(s, e, rect);
             Dispatcher.Invoke(() => _canvas.Children.Add(rect.Rectangle));
         }
     }
 }
Пример #2
0
 private void RectOnMouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs, MyRectangle rectangle)
 {
     if (CanToggleBlock)
     {
         _game.Toggle(rectangle.X, rectangle.Y);
         Draw();
     }
 }