2天前,我问了一个关于国际象棋游戏的问题,并且一位朋友向我推荐了下面的代码,并且对此有疑问。 it was this link将图像插入国际象棋游戏中的代码c#
请参阅: private image Displayimage;
我不知道我应该怎样把棋子的图像放在里面,我应该把它放在哪里? 类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
}
}
你已经有一个'私人Image DisplayedImage;'这里有什么问题? – 2010-11-06 11:08:52
在一个稍微不相关的说明中,我将ChessPiece类标记为“抽象”类,因为您永远不会想要创建通用棋子的实例。你仍然可以使用ChessPiece作为基类来引用任何特定类型的棋子。 – 2010-11-06 11:29:46