i asked a question about chess game 2days ago,and a friend suggest me the code below,and i have question about it.it was this link
please see: private image Displayimage;
i don't know how should i put images from pieces of chess game in it,and where should i put it? class PiecePosition {
public enum ChessColor
{
White,
Black,
}
public class ChessPiece
{
private Image DisplayedImage;
private ChessColor DisplayedColor;
private Point CurrentSquare;
private Point[] ValidMoves;
public ChessPiece(Image image, ChessColor color)
{
DisplayedImage = image;
DisplayedColor = color;
}
}
public class KingPiece : ChessPiece
{
public KingPiece(Image image, ChessColor color)
: base(image, color)
{
ValidMoves[0] = new Point(0, -1); // Up 1
ValidMoves[1] = new Point(1, -1); // Up 1, Right 1
ValidMoves[2] = new Point(1, 0); // Right 1
ValidMoves[7] = new Point(-1, -1); // Left 1, Up 1
}
}
public class Board
{
private ChessPiece[,] square;
private int SquareWidth; // Number of pixels wide
private int SquareHeight; // Number of pixels high
}
}
If you're wondering how you can compile the images along with your source code and then access them, the easiest way is to add the images to your project using Resources. This allows you to easily add external files as embedded resources in your project that will be compiled directly into your executable.
To add a resource to your project, follow these steps:
Now that you've added resources to your project file, you can use them in your code like this (all of the access details are handled automatically by the ResourceManager class):
System.Drawing.Bitmap kingImage = MyChessGame.Properties.Resources.KingImage;
KingPiece kingPiece = new KingPiece(kingImage, ChessColor.White);