-
Notifications
You must be signed in to change notification settings - Fork 5
5. Architecture
MonoBehaviour classes placed on unity GameObjects
Main class, it controls general game stuff. Script placed at the main "Board" GameObject
-
Game related functions:
- Switch turn when a player moves a piece.
- Check if a player lost (checkmate).
-
Squares related functions:
- Get the closest square from a position in the scene.
- Hover all squares the piece can move to.
- Check if squares between the king and a castling tower are not targeted by an enemy.
-
Pieces related functions:
- Check if the king is in check.
- Destroy a piece when it's eaten.
This class represents a piece in the board. Script placed on each "Piece" GameObject
-
Moves related functions:
- Depending of the piece, it will have different allowed moves (for example, a bishop will only be able to move diagonally), there are multiple functions to check the different allowed moves.
- Once the piece is moved to a valid square, its position is updated.
- Castling system
A standard chessboard has 64 squares in total, 32 white and 32 black. This class is used to update its colors & the piece its holding at the moment. Script placed on each "Square" GameObject
Extra classes used to represent specific elements of the chess game.
Since we need to represent board squares, this class is used to hold the x & y axes and the Transform position of the GameObject, no functions required.
This class is used to represent a piece move. It saves the x & y position of the movement (starting from the piece position) and the type of move (eat, move, jump, etc)
Each type of piece has different types of moves, this enumerator is used to represent these moves, we can distinguish 5 different types:
- StartOnly: This move will be allowed until the piece is moved for the first time, this type of move is also used in the castling system.
- Move: Standard move, when a piece moves to a free square.
- Eat: When the piece moves to a square that is holding an enemy piece and this piece can eat enemy pieces.
- EatMove: Piece can move to a free square or eat an enemy.
- EatMoveJump: This type of move is basically like the EatMove but it has no restrictions in the direction (this piece can jump pieces that are on the way of destination square)
User Interface and interaction
Script placed on each "Piece" GameObject. It controls interaction with pieces, drag and drop it where we want.
Camera control, change perspective when turn changes