This is a native Java implementation of the classic Tic Tac Toe game. The game features a graphical user interface (GUI) built using Swing
, offering smooth gameplay with automatic win/draw detection.
Click the image above to watch the gameplay video.
- Two-player gameplay: Play with friends using classic Tic Tac Toe rules.
- GUI built with Swing: Intuitive interface for quick interactions.
- Dynamic game logic: The game checks for winners and draws automatically.
- Java Development Kit (JDK) installed (version 8 or higher)
- Git installed
- Open your terminal and clone the repository:
git clone https://github.com/Omid2831/Tic-tac-toe.git
- Navigate into the project directory:
cd Tic-tac-toe
- Compile the source files and place the compiled classes in the
bin
directory:
javac -d bin *.java
- Run the program:
java -cp bin main
📂 Tic-tac-toe ├── main.java # Main entry point of the application ├── TikTakToe.java # Game logic and GUI implementation ├── main.class # Compiled bytecode for main ├── TikTakToe.class # Compiled bytecode for game logic ├── 📂 capture │ ├── Demo.mp4 # Gameplay video │ └── pic.png # Screenshot of the game
The game operates as follows:
-
Game Setup
- The game is played on a 3x3 grid.
- Two players take turns to mark their respective symbols (
X
orO
).
-
Gameplay
- The GUI dynamically updates to reflect each player's move.
- Players alternate turns until a win, draw, or loss condition is met.
-
Game Result Detection
- The program checks for the following outcomes:
- Wins:
- Three aligned marks (horizontally, vertically, or diagonally).
- Loss:
- The other player achieves three aligned marks.
- Draws:
- The board is full, and no player has achieved three aligned marks.
- Wins:
- The program checks for the following outcomes:
-
Feedback
- The GUI highlights:
- Winning cells if a player wins.
- A message indicates the game result (win, loss, or draw).
- The GUI highlights: