summaryrefslogtreecommitdiff
path: root/ChessPiece.cs
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2020-09-02 11:08:17 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2020-09-02 11:08:17 +0200
commit4811afb52c511565d2b13f36ed645243c7557803 (patch)
tree3533dc4a8dfb5ed610033e0b9c527a535be6143b /ChessPiece.cs
board generation
Diffstat (limited to 'ChessPiece.cs')
-rw-r--r--ChessPiece.cs50
1 files changed, 50 insertions, 0 deletions
diff --git a/ChessPiece.cs b/ChessPiece.cs
new file mode 100644
index 0000000..68bc1cf
--- /dev/null
+++ b/ChessPiece.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Drawing.Imaging;
+
+namespace Chess
+{
+ public abstract class ChessPiece
+ {
+ internal Bitmap PieceImage;
+ internal bool IsWhite;
+
+ public ChessPiece(bool isWhite)
+ {
+ IsWhite = isWhite;
+ }
+
+ public abstract bool MoveTo();
+ public abstract void Draw(Graphics graphics, float x, float y, float tileWidth, float tileHeight);
+
+ public Bitmap ResizeImage(Image image, int width, int height)
+ {
+ var destRect = new Rectangle(0, 0, width, height);
+ var destImage = new Bitmap(width, height);
+
+ destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
+
+ using (var graphics = Graphics.FromImage(destImage))
+ {
+ graphics.CompositingMode = CompositingMode.SourceCopy;
+ graphics.CompositingQuality = CompositingQuality.HighQuality;
+ graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
+ graphics.SmoothingMode = SmoothingMode.HighQuality;
+ graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
+
+ using (var wrapMode = new ImageAttributes())
+ {
+ wrapMode.SetWrapMode(WrapMode.TileFlipXY);
+ graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
+ }
+ }
+
+ return destImage;
+ }
+ }
+}