public Hard() { InitializeComponent(); Random cube = new Random(); Board.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Board.Arrange(new Rect(0.0, 0.0, Board.DesiredSize.Width, Board.DesiredSize.Height)); for (int i = 0; i < cellwide; i++) //a ciklus feltölti a gridet { for (int j = 0; j < cellhigh; j++) { Rectangle r = new Rectangle(); r.Width = Board.ActualWidth / cellwide - 2.0; //aktuális szélesség r.Height = Board.ActualHeight / cellhigh - 2.0; //aktuális magasság r.Fill = (cube.Next(0, 2) == 1) ? Brushes.DarkMagenta : Brushes.Gray; //kitöltés Board.Children.Add(r); Canvas.SetLeft(r, j * Board.ActualWidth / cellwide); Canvas.SetTop(r, i * Board.ActualHeight / cellhigh); r.MouseDown += R_MouseDown; area[i, j] = r; } } timer.Interval = TimeSpan.FromSeconds(0.1); timer.Tick += Timer_Tick; }