This Program It is a chess game for my students. If you are interested in it, you can download it and check it out.
A virtual grid is drawn, and the grid distribution is 9x10. The grid layout is the same as the regular chess layout, that is, gridx and gridy are used as the X and Y coordinates of the grid, all coordinate points are converted using this virtual Mesh
A chess part interface is defined, and the interaction between all chess boards and chess pieces comes from this interface. Public Interface Ichessitem
{
/**/ /// <Summary>
///Is it blue or red?
/// </Summary>
Enums. chesstype type {Get;Set;}
/**/ /// <Summary>
///Pressed or not
/// </Summary>
Bool Ischecked {Get;Set;}
/**/ /// <Summary>
///Moving step x
/// </Summary>
Int Stepx {Get;}
/**/ /// <Summary>
///Moving step y
/// </Summary>
Int Stepy {Get;}
/**/ /// <Summary>
///X coordinates in the checker Mesh
/// </Summary>
Int Gridx {Get;Set;}
/**/ /// <Summary>
///Y coordinate in the checker Mesh
/// </Summary>
Int Gridy {Get;Set;}
/**/ /// <Summary>
/// Move pawns
/// </Summary>
/// <Param name = "chessx"> X coordinate of the grid to be moved </Param>
/// <Param name = "Chessy"> Y coordinate of the grid to be moved </Param>
/// <Returns> Whether to move successfully </Returns>
Bool Moveitem ( Int Chessx, Int Chessy );
/**/ /// <Summary>
///Initialize pawns
/// </Summary>
Void Inititem ();
/**/ /// <Summary>
///Remove the pawns and eat them as other pawns.
/// </Summary>
Void Remove ();
}
There are two important events.
Private Void Cib_click ( Object Sender, eventargs E)
This event is a stepping stone event. It responds to the selected pawns and eats other pawns. The name has not been changed. Sorry.
Private Void Form1_mousedown ( Object Sender, system. Windows. Forms. mouseeventargs E)
This event moves as a pawn
The movement of all pawns comes fromBoolMoveitem (IntChessx,IntChessy );
Because it is for my students, this program is relatively simple, so the process is relatively simple. If you are a friend of C #, let's take a look.
WhereAlgorithmThe trouble is that the guns go through the mountains, the horses are lame, and the elephants are lame.
All pawns inherit the chessitembase. Some pawns rewrite the Public Virtual bool limitpoint (INT chessx, int Chessy) function to implement their own special movement restrictions, such as guns, horses, elephants,Soldiers, etc.
Demo soure