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 {/**///////to Blue or red
of the grid to be moved /// Y coordinate of the grid to be moved /// Whether to move successfully Bool Moveitem ( Int Chessx, Int Chessy ); /**/ //////Initialize pawns/// Void Inititem (); /**/ //////Remove the pawns and eat them as other pawns./// Void Remove ();}
There are two important events.
Private
Void
Cib_click (
Object
Sender, eventargs E)
This event is a stepping stone event. It respon
message = ""; String blackMessage = "unlimited"; String whiteMessage = "unlimited"; // Save the score, records the position of each step. int [] chessX = new int [255]; int [] ChessY = new int [255]; int countX, countY; // default value: int maxTime = 0; // maximum time int blackTime = 0; int whiteTime = 0; // Save the remaining time of the black and white side Thread timer = new Thread (this); public FiveChessFrame () {this. setTitle ("wuziqi game")
* 30-2,15 + J * 30-2,13,15 + i * 30-2,15 + J * 30-2,0) if(Me) {//Black ChessGradient.addcolorstop (0, ' #0a0a0a ') Gradient.addcolorstop (1, ' #636766 ') }Else{//White ChessGradient.addcolorstop (0, ' #d1d1d1 ') Gradient.addcolorstop (1, ' #f9f9f9 ')} Ctx.fillstyle=gradient Ctx.fill ()}View CodeStep four: When clicking on the intersection of the chessboard, draw the pieces1. Use E.offsetx, e.offsety to get the offset of the current click position relative to the canvas origin2. Calculate
Lazi position int[]chessx=new int[255]; Int[]chessy=new int[255]; int countx,county;//default setting no time limit int maxtime=0; Save max Time int blacktime=0;int whitetime=0; Save the time remaining in the black and white side thread timer=new thread (this); Public Fivechessframe () {this.settitle ("Gobang Game"); This.setsize (This.setlocation (width-500)/2, (height-500)/2); This.setresizable (FALSE); This.setdefaultcloseoperation (
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.