C # Implementation of the Chess game program

Source: Internet
Author: User
Tags bool

This program is for my students to do a chess game, which involves all interested friends can download to see

It draws a virtual grid, where the grid distribution is 9x10 distribution, and normal chess layout, that is, gridx,gridy as the x,y coordinates of the grid, all coordinate points are converted using this virtual grid

It defines a piece interface, and all the interactions between the board and the pieces come from this interface.

public interface Ichessitem
{
/**////<summary>
///to Blue or red to
///</summary>
Enums.chesstype Type{get;set;}
/**////<summary>
///is pressed
///</summary>
BOOL Ischecked{get;set;
/**////<summary>
///move step x
///</summary>
int stepx{get;}
/**////<summary>
///move step y
///</summary>
int stepy{get;}
/**////<summary>
///The x-coordinate of the checkerboard grid
///</summary>
int gridx{get;set;}
/**////<summary>
///The y-coordinate in the checkerboard grid
///</summary>
int gridy{get;set;}
/**////<summary>
///Move Pawn
///</summary>
///<param name= "CHESSX" > grid x coordinates to be moved </ Param>
///<param name= "Chessy" > The grid y-coordinate to be moved </param>
///<returns> whether to move successfully </returns>
BOOL MoveItem (int chessx,int chessy);
/**////<summary>
///Initialize the pawn
///</summary>
void Inititem ();
/**////<summary>
///to remove the pawn as it is eaten by another pawn
///</summary>
void Remove ();
}

There are two more important events private void Cib_click (object sender, EventArgs e) This event for the pawn to click the event, by which to respond to the selection of pieces and eat other pieces, the name did not change, oh, sorry

private void Form1_mousedown (object sender, System.Windows.Forms.MouseEventArgs e) This event is moved as a pawn

All pieces are moved from the Ichessitem interface.

BOOL MoveItem (int chessx,int chessy);

Because it is for my students to see, this program is simpler, so the flow is relatively simple. Learn C # friends can look at, hehe

One of the algorithms trouble is the cannon of the turn of the mountain, the horse's lame, like the lame

All pieces inherit chessitembase, some of which override the function public virtual bool Limitpoint (int chessx,int Chessy) to achieve their own special restrictions to move, such as artillery, horses, elephants, soldiers, etc.

Demo Soure Http://www.cnblogs.com/Files/KeithDan/Chess.rar

Http://www.cnblogs.com/KeithDan/archive/2006/12/06/583472.html

Related Article

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.