C # a chess game program

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.