How to make a game similar to chess
Hey guys I'm trying to build a game that is similar to chess and I have no idea how to code it using C#. I already have made a chessboard made from a bunch of plains and I put them all under one empty game object I named "GameBoard". I just really need help with how and what I need to code because I honestly have no idea. I've watched some YouTube videos on this subject but none of them are starting out with a game board created from scratch like I did.
So what I'm basically asking for help with the coding with the board and the pieces. Like how to I make code so pieces can move in certain patterns like they do in chess? And how do I make code for the pieces to "snap" (I guess you would call it) to the board with a mouse click?
Sorry if I made anything unclear, but all help is valuable!
Answer by Cloaked_One · Dec 08, 2016 at 07:29 PM
This is what I did:
Make an array of 101. 65 for the GameBoard and 36 for the border. Then in Unity drag each tile object into an element in the array.
Assign each tile a variable to store the number of it's element in the array.
Put your pieces as children of your tiles.
Write your Piece behaviors. Have your piece find the tile element it's on, take that number and add or subtract 1, 7, 8, or 9. and enable particle effects of that tile.
OnMouseDown(0) is what I use to interact with Pieces and Tiles. when a piece is clicked it toggles a bool signifying that that a piece is selected. stores this piece in a variable on the Gameboard. calls your behavior highlighting tiles that you can move to.
Then click a tile, and if this tile has particle effects enabled, takes the piece stored on the GameBoard Variable and reparents that piece to your clicked tile.
These are some of the big steps that will put you on track for getting piece movement. If you have specific questions about my steps or the code in those steps, I'll post some of my code. I just hesitate putting it all up here as...
I'm self taught and new to coding
I'm sure it could be written better
It's taken me almost 1 yr to get my 2500+ lines that make up piece movement, movement obstruction, and capture .