private void CreateGrid(string gridname, int width, int height, int marginleft, int margintop, int griddistance) { int a = 0; int b = 0; for (int j = 0; j < 10 * height; j += height) { for (int i = 0; i < 10 * width; i += width) { Rectangle rect = new Rectangle(); HitState.HitValue hitvalue = HitState.HitValue.Empty; var gridSquare = new GridSquare(rect, hitvalue); game.GridSquares.Add(gridSquare); rect.StrokeThickness = 1; rect.Stroke = _blackBrush; rect.Width = width; rect.Height = height; rect.Fill = _blueBrush; rect.Name = $"{gridname}_{b}_{a}"; if (gridname == "fleet") { rect.MouseLeftButtonDown += FleetGrid_MouseLeftButtonDown; rect.MouseRightButtonDown += FleetGrid_MouseRightButtonDown; } Canvas.SetLeft(rect, i + marginleft); Canvas.SetTop(rect, j + griddistance + margintop); _rectangles.Add(rect); b++; } a++; b = 0; } }
public GridSquare(Rectangle rectangle, HitState.HitValue wasHit) { this.WasHit = HitState.HitValue.Empty; this._rectangle = rectangle; }