A fully-featured, two-player chess game built with Java Swing, wrapped in an elegant ancient-themed dark wood UI with gold accents. Play classic chess on a beautiful graphical interface complete with animated piece movement, a configurable chess clock, legal move highlighting, check detection, checkmate/stalemate resolution, pawn promotion, castling, en passant, and more.
| Feature | Description |
|---|---|
| Ancient-Themed UI | Dark wood background with gold accents, serif fonts, and ornate styled panels |
| Chess Clock / Timer | Selectable time controls: ∞ (no limit), 1 min, 3 min, 5 min, or 10 min per player |
| Turn Indicator | Prominent sidebar display showing whose turn it is, with distinct styling for White and Black |
| Graphical Board | 8×8 board with warm parchment & walnut squares, gold-labeled rows (1–8) and columns (A–H) |
| Unicode Pieces | Beautiful Unicode chess symbols — no image assets required |
| Legal Move Highlighting | Click a piece to see valid moves highlighted in gold; selected piece highlighted in sage green |
| Smooth Animations | Pieces glide from source to destination with an arc animation |
| Castling | King-side and queen-side castling fully implemented |
| En Passant | Special pawn capture rule correctly enforced |
| Pawn Promotion | Themed dialog lets you choose Queen, Rook, Bishop, or Knight on promotion |
| Check Detection | King under threat is highlighted in crimson |
| Checkmate & Stalemate | Game-ending conditions detected and announced with a styled dialog |
| Move History | Scrollable sidebar with algebraic-style notation (e.g. ♙ E2 → E4) |
| Captured Pieces | Separate panels display captured white and black pieces |
| Reset / New Game | Reset with same time control, or start a new game with a different one |
The project follows a clean object-oriented design with separation of concerns between game logic and presentation.
ChessGame/
├── src/
│ └── chess/
│ ├── Main.java # Application entry point
│ ├── ChessGUI.java # Swing GUI — board rendering, click handling, animations
│ ├── ChessGame.java # Core game logic — turns, check, checkmate, special moves
│ ├── Board.java # Board state — 8×8 grid of pieces
│ ├── Piece.java # Abstract base class for all chess pieces
│ ├── Move.java # Data class representing a move (start → end)
│ ├── InvalidMoveException.java# Custom exception for illegal moves
│ ├── Tile.java # Tile representation
│ ├── Pawn.java # ♙ Pawn — includes double-step, en passant tracking
│ ├── Rook.java # ♖ Rook — horizontal/vertical sliding
│ ├── Knight.java # ♘ Knight — L-shaped jumps
│ ├── Bishop.java # ♗ Bishop — diagonal sliding
│ ├── Queen.java # ♕ Queen — combined rook + bishop movement
│ └── King.java # ♔ King — single-step + castling logic
├── out/ # Compiled .class files (generated)
├── INSTALLATION.md # Installation & run guide
└── README.md # This file
┌──────────┐
│ Main │
└────┬─────┘
│ creates
┌────▼─────┐
│ ChessGUI │ ◄── Swing UI, event handling, animation
└────┬─────┘
│ manages
┌────▼──────┐
│ ChessGame │ ◄── Turn management, move validation, special rules
└────┬──────┘
│ operates on
┌────▼─────┐
│ Board │ ◄── 8×8 Piece[][] grid
└────┬─────┘
│ contains
┌────▼─────┐
│ Piece │ (abstract)
└────┬─────┘
┌───────┬──────┼──────┬────────┬────────┐
│ │ │ │ │ │
Pawn Rook Knight Bishop Queen King
Prerequisites: Java Development Kit (JDK) 11 or higher
# Clone the repository
git clone https://github.com/<your-username>/2-Player-Chess-Java--Swing-.git
cd 2-Player-Chess-Java--Swing-
# Compile
javac -encoding UTF-8 -d out src/chess/*.java
# Run
java -cp out chess.MainFor detailed setup instructions, see the Installation Guide.
- Launch the application — a time control dialog appears first.
- Select a time control: ∞ (no limit), 1 min, 3 min, 5 min, or 10 min.
- The board opens maximized. The sidebar shows whose turn it is and (if timed) each player's remaining clock.
- Click a piece to select it. The selected piece turns green and all legal destination squares turn gold.
- Click a highlighted square to move the piece. The piece animates to its new position.
- Turns alternate between White and Black after each valid move.
- Check: If a king is in check, its square turns crimson red.
- Promotion: When a pawn reaches the opposite end, a themed dialog appears to choose a promotion piece.
- Castling: Move the king two squares toward a rook to castle (if legal).
- Timer: If a player's clock runs out, they lose. The timer turns red at ≤10 seconds.
- Game Over: Checkmate, stalemate, or time-out is announced via a styled dialog.
- Reset: Click "↺ Reset" to restart with the same time control, or "♔ New Game" to pick a new one.
| Tool | Version |
|---|---|
| JDK | 11+ (tested on 17 & 21) |
| OS | Windows, macOS, or Linux |
| IDE (optional) | VS Code, IntelliJ IDEA, Eclipse |
# Compile all source files with UTF-8 encoding (required for Unicode piece symbols)
javac -encoding UTF-8 -d out src/chess/*.javaThe -encoding UTF-8 flag is required because the source files contain Unicode chess piece characters (♔ ♕ ♖ etc.).
# Via the Main entry point
java -cp out chess.Main
# Alternative: directly via ChessGUI (also has a main method)
java -cp out chess.ChessGUI- Undo / Redo move functionality
- AI opponent (single-player mode)
- Sound effects for moves and captures
- Highlight the last move played
- Dynamic window resizing for board and pieces
- PGN export / import for game records
- Additional themes (marble, modern minimalist)
Contributions are welcome! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Commit your changes:
git commit -m "Add my feature" - Push to the branch:
git push origin feature/my-feature - Open a Pull Request
Please make sure your code compiles cleanly with javac -encoding UTF-8 -d out src/chess/*.java before submitting.
This project is open source and available under the MIT License.
Made with ♟️ and Java