summaryrefslogtreecommitdiff
path: root/BoardTile.cs
diff options
context:
space:
mode:
authorRamaekers,Aldrik A.N <a.ramaekers@student.fontys.nl>2020-09-03 14:40:33 +0200
committerRamaekers,Aldrik A.N <a.ramaekers@student.fontys.nl>2020-09-03 14:40:33 +0200
commit5a045404f3c49022abeb75c27dfe6f82d35928f7 (patch)
treea1dd8aa4091e9bf8d4377dc6d6f26cc9ca07ce47 /BoardTile.cs
parent4811afb52c511565d2b13f36ed645243c7557803 (diff)
board setup and chess piece movement checks
Diffstat (limited to 'BoardTile.cs')
-rw-r--r--BoardTile.cs38
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);
+ }
}
}
}