This is a Chess Game project developed as part of the Object-Oriented Programming course at Seoul National University of Science and Technology (SeoulTech). The project was quickly put together in a day using C++.
- Initial Piece Placement: Pieces are placed in standard positions at the start of the game.
- Turn Management: Turns alternate between players, and the current turn is indicated.
- Piece Selection: Players can select pieces, and the selection is visually indicated.
- Valid Moves Highlighting: Shows all possible moves for the selected piece.
- Piece Movement: Allows players to move pieces to valid positions.
- Board Update: The board updates to reflect moves, including capturing opponent pieces.
- Check/Checkmate Indication: Visual and/or audio indication of check or checkmate situations.
- Game Result Display: Displays the game's outcome, and disables further moves once a winner is determined.
-
paint()
- Calls the parent class
ChessBoard
's paint method to draw the base chessboard. - Highlights the currently selected piece and possible move locations.
- Displays the current game state (ongoing, check, win, etc.).
- Calls the parent class
-
mouseDown(int x, int y)
- Handles mouse click events to select or move pieces based on the clicked location.
- Calculates possible moves for the selected piece and performs the move if valid.
-
switchPlayer()
- Changes the current player, called at the end of a turn.
-
calculatePossibleMoves(int x, int y)
- Computes all possible moves for the selected piece.
-
movePiece(const std::pair<int, int>& from, const std::pair<int, int>& to)
- Moves a piece from one location to another, checks move validity, and updates the game state.
-
isValidMove(...)
- Validates whether a move is legal for a given piece, implemented through the
Piece
class'sisValidMove
method.
- Validates whether a move is legal for a given piece, implemented through the
-
canSelect(int row, int col)
- Checks if the current player can select a piece at the given position.
-
findKingPosition(Player currentPlayer)
- Finds the position of the current player's king.
-
isCheck()
- Determines if the current player's king is in check.
-
drawChessBoard()
- Draws each tile of the chessboard, with colors determined by position.
-
initializeBoard()
- Places pieces in their initial positions at the start of the game.
-
drawPieces()
- Renders each piece on the chessboard according to its type and position.
-
drawText(const TCHAR text, int length, int x, int y)
- Draws text at the specified position.
-
drawPiece(const Piece piece, int x, int y)
- Draws a specific piece at the given position.
Each chess piece's movement rules are implemented in the isValidMove
method of its respective class.
-
Pawn
- Moves forward one square, or two squares from its initial position. Captures diagonally.
-
Knight
- Moves in an 'L' shape: two squares in one direction and then one square perpendicular.
-
Bishop
- Moves diagonally any number of squares, without jumping over other pieces.
-
Rook
- Moves vertically or horizontally any number of squares, without jumping over other pieces.
-
Queen
- Moves vertically, horizontally, or diagonally any number of squares.
-
King
- Moves one square in any direction.