public void Create(IEngine engine) { if (engine == null) return; Engine = engine; Field = Engine.Field; Engine.PlayerSetWall += OnSetWall; Engine.PlayerMove += UpdatePos; Engine.PlayerChanged += UpdatePos; grid.Children.Clear(); grid.ColumnDefinitions.Clear(); grid.RowDefinitions.Clear(); int n = Field.Dimension; int m = Field.Dimension; for (int j = 0; j < m - 1; ++j) { grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(16, GridUnitType.Pixel) }); } grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); for (int i = 0; i < n - 1; ++i) { grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(16, GridUnitType.Pixel) }); } grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) { Rectangle r = new Rectangle() { Fill = ((i + j) % 2 == 0) ? Brushes.LightSkyBlue : Brushes.LightSlateGray, Margin = new Thickness(-8) }; grid.Children.Add(SetSell(r, i, j)); #if DEBUG grid.Children.Add(SetSell(new Label() { Content = (i * n + j).ToString() }, i, j)); #endif } for (int i = 0; i < n - 1; ++i) for (int j = 0; j < m - 1; ++j) { int i0 = i; int j0 = j; Rectangle r = new Rectangle() { Fill = Brushes.Black, Margin = new Thickness(-1) }; r.MouseLeftButtonDown += (s, e) => Engine.PostSetWall(i0, j0, WallStyle.Horizontal); r.MouseRightButtonDown += (s, e) => Engine.PostSetWall(i0, j0, WallStyle.Vertical); Grid.SetRow(r, 1 + 2 * i); Grid.SetColumn(r, 1 + 2 * j); grid.Children.Add(r); } player1 = new Ellipse() { Fill = Brushes.IndianRed, Stroke = Brushes.Black }; grid.Children.Add(SetSell(player1, Field.Hero1.Y, Field.Hero1.X)); player2 = new Ellipse() { Fill = Brushes.DarkBlue, Stroke = Brushes.Black }; grid.Children.Add(SetSell(player2, Field.Hero2.Y, Field.Hero2.X)); arrowDown = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow }; arrowRight = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow }; arrowLeft = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow }; arrowUp = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow }; arrowDown.MouseDown += (s, e) => Engine.PostMove(0, +1); arrowUp.MouseDown += (s, e) => Engine.PostMove(0, -1); arrowLeft.MouseDown += (s, e) => Engine.PostMove(-1, 0); arrowRight.MouseDown += (s, e) => Engine.PostMove(+1, 0); UpdatePos(null, null); }