diff options
Diffstat (limited to 'BoardTile.cs')
| -rw-r--r-- | BoardTile.cs | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/BoardTile.cs b/BoardTile.cs index 1bccbec..e58cbc6 100644 --- a/BoardTile.cs +++ b/BoardTile.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Drawing; using System.Linq; using System.Text; @@ -19,20 +20,47 @@ namespace Chess public int Y; public BoardTileColor Color; public ChessPiece OccupyingPiece; - https://git.fhict.nl/I436104/chess - public BoardTile(int x, int y, BoardTileColor color) + + public BoardTile(int x, int y) { X = x; Y = y; - Color = color; + + Color = BoardTileColor.White; + if (y % 2 == 0) + { + if (x % 2 != 0) Color = BoardTileColor.Black; + } + else + { + if (x % 2 == 0) Color = BoardTileColor.Black; + } + OccupyingPiece = null; } - internal void Draw(Graphics graphics, float tileWidth, float tileHeight) + public bool CanMoveTo(ChessBoard board, BoardTile tile) { - graphics.FillRectangle(new SolidBrush(this.Color == BoardTileColor.White ? System.Drawing.Color.White : System.Drawing.Color.Black), new RectangleF(X * tileWidth, Y * tileHeight, tileWidth, tileHeight)); + if (OccupyingPiece != null) return OccupyingPiece.CanMoveTo(board, this, tile); + + return false; + } + + internal void Draw(Graphics graphics, float tileWidth, float tileHeight, bool active) + { + graphics.FillRectangle(new SolidBrush(this.Color == BoardTileColor.White ? System.Drawing.Color.FromArgb(235, 236, 208) : System.Drawing.Color.FromArgb(137, 163, 105)), + new RectangleF(X * tileWidth, Y * tileHeight, tileWidth, tileHeight)); OccupyingPiece?.Draw(graphics, X, Y, tileWidth, tileHeight); + + if (active) + { + float marginw = tileWidth / 3; + float marginh = tileHeight / 3; + int padding = 3; + graphics.FillEllipse(new SolidBrush(System.Drawing.Color.FromArgb(150, 50, 50, 50)), X * tileWidth + marginw, Y * tileHeight + marginh, tileWidth - marginw * 2, tileHeight - marginh * 2); + graphics.FillEllipse(new SolidBrush(System.Drawing.Color.FromArgb(150, 255, 200, 200)), X * tileWidth + marginw + padding, Y * tileHeight + marginh + padding, tileWidth - (marginw + padding) * 2, tileHeight - (marginh + padding) * 2); + } } } } |
