private void DrawSquares(Graphics g) { Squares.Clear(); for (var r = Rank._1; r <= Rank._8; r++) { for (var f = File.A; f <= File.H; f++) { var x = Flipped ? Left + (Side - ((int)f + 1) * SquareSide) : Left + (int)f * SquareSide; var y = Flipped ? Top + ((int)r * SquareSide) : Top + Side - ((int)r + 1) * SquareSide; var chessSquare = Game.Board.Square(f, r); var brush = chessSquare.Color == Chess.Color.Black ? DarkBrush : LightBrush; var rect = new RectangleF(x, y, SquareSide, SquareSide); g.FillRectangle(brush, rect); var circleRect = rect; circleRect.Inflate(-SquareSide * 0.75f, -SquareSide * 0.75f); if (HiLights.Contains(chessSquare)) { g.FillEllipse(_hiLightBrush, circleRect); } var lastMove = Game.OtherPlayer.Moves.FirstOrDefault(); if (lastMove != null) { if (lastMove.FromSquare == chessSquare || lastMove.ToSquare == chessSquare) { g.FillRectangle(LastMoveBrush, rect); } } Squares.Add(chessSquare, rect); if (chessSquare.Piece != null && MouseDownSquare != chessSquare) { if (_animationOffset == null || chessSquare.Piece != _animationOffset.Item1) { DrawPiece(chessSquare, rect, g); } } //g.DrawString(chessSquare.ToString(), new Font(FontFamily.GenericSansSerif, 12), Brushes.Red, x + SquareSide / 16, // y + SquareSide / 4); } if (MouseDownSquare?.Piece != null) { var x = MouseX - SquareSide / 2; var y = MouseY - SquareSide / 2; var rect = new RectangleF(x, y, SquareSide, SquareSide); DrawPiece(MouseDownSquare, rect, g); } if (_animationOffset != null && _animationOffset.Item1 != null) { var rect = new RectangleF(_animationOffset.Item2.X, _animationOffset.Item2.Y, SquareSide, SquareSide); DrawPiece(_animationOffset.Item1.Square, rect, g); } } }
private void CreateSquares() { Squares.Clear(); Enumerable.Range(0, Rows) .SelectMany(x => Enumerable.Range(0, Columns) .Select(y => new Square { Row = x, Column = y })) .ToList().ForEach(Squares.Add); }
private void DrawSquares(Graphics g) { Squares.Clear(); for (var r = Rank._1; r <= Rank._8; r++) { for (var f = File.A; f <= File.H; f++) { var x = Flipped ? Left + (Side - ((int)f + 1) * SquareSide) : Left + (int)f * SquareSide; var y = Flipped ? Top + ((int)r * SquareSide) : Top + Side - ((int)r + 1) * SquareSide; var chessSquare = Game.Board.Square(f, r); var brush = chessSquare.Color == Chess.Color.Black ? DarkBrush : LightBrush; if (MouseDownSquare == chessSquare) { brush = new SolidBrush(ControlPaint.LightLight(((SolidBrush)brush).Color)); } var rect = new RectangleF(x, y, SquareSide, SquareSide); g.FillRectangle(brush, rect); if (HiLights.Contains(chessSquare)) { g.FillRectangle(_hiLightBrush, rect); } Squares.Add(chessSquare, rect); if (chessSquare.Piece != null && MouseDownSquare != chessSquare) { if (_animationOffset == null || chessSquare.Piece != _animationOffset.Item1) { DrawPiece(chessSquare, rect, g); } } //g.DrawString(chessSquare.ToString(), new Font(FontFamily.GenericSansSerif, 12), Brushes.Red, x + SquareSide / 16, // y + SquareSide / 4); } if (MouseDownSquare?.Piece != null) { var x = MouseX - SquareSide / 2; var y = MouseY - SquareSide / 2; var rect = new RectangleF(x, y, SquareSide, SquareSide); DrawPiece(MouseDownSquare, rect, g); } if (_animationOffset != null && _animationOffset.Item1 != null) { var rect = new RectangleF(_animationOffset.Item2.X, _animationOffset.Item2.Y, SquareSide, SquareSide); DrawPiece(_animationOffset.Item1.Square, rect, g); } } }
private void CreateItems() { Squares.Clear(); Route.Clear(); for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { Squares.Add(new GridItem() { Row = i, Column = j }); } } }
private void Clear(object sender, RoutedEventArgs e) { Squares.Clear(); }