What is the simplest or easiest method to make a chess game?

I am creating Chinese chess for my school project. I only have around 1 and a half years of coding experience and have never created a game. I realize after I create the game interface, I totally have no idea what should I do next.

I have no idea how to make the picture clickable like real pieces, connect pieces to their own algorithm and etc. I have been stuck for around 1 week and nearly give up. Can someone give me some suggestions to tell me what should I do next?

1 Like

I think you have a rather large undertaking and probably too much for one forum thread (or one school project for that matter). Just throwing stuff out there, but what I would do is start with a 2d array (looks like 9x10?) of possible positions for each piece. Each piece could be represented by a char or a string I guess, to start with. Fill the array with starting positions. Then in the draw step, read the array and draw the appropriate piece texture, multiplying the array positions by whatever size (32, 64, whatever) in pixels to space them out.

For a move, figure out click and drag with snapping. Then write back to the array when the mouse button is lifted, dividing and rounding with whatever offset the position of the moved piece and converting to an int to get back to the array slot you want. The simplest thing to do for capture would be when the array changes it just overwrites what was there previously, so a piece is “taken.” So now, any piece can be clicked and dragged to any valid position on the board, and it will take the piece that was there before.

Then… implement the logic of each piece, determining what is or isn’t a valid move.

2 Likes

You have given me some idea. Thank you so much for this.

Technically, stealing.

For this, look at Mouse.GetState(). You can call this in your Update method and it will return the current state of the mouse for that frame only. This includes the position, state of the buttons (up or down), and the scroll wheel. If you store the state of the previous frame somewhere, you can compare the previous state with the current state to tell if the mouse has been clicked down, or released.

@differenceclouds has given you some insight into how to track your data and draw your board. You can use this, in conjunction with the mouse positions and state, to check whether or not the mouse is over or near a piece, and whether or not a user has clicked.

Good luck! :slight_smile:

2 Likes