This is a simple Tic-Tac-Toe game implemented in Java. The game is designed for two players, where Player 1 uses the symbol 'X' and Player 2 uses the symbol 'O'. The players take turns to mark a 3x3 grid, aiming to place three of their symbols in a horizontal, vertical, or diagonal row.
- Two-player mode
- Interactive command-line interface
- Input validation to ensure valid moves
- Automatic detection of win, loss, or draw
- Easy-to-understand game logic and structure
- Java Development Kit (JDK) 8 or higher
- Basic knowledge of running Java applications from the command line
-
Clone or Download the Repository: Clone this repository to your local machine using:
-
Compile the Code: Open a terminal and navigate to the directory containing the Java files. Compile the code using the
javaccommand:javac TicTacToe.java
-
Run the Game: After compiling, you can start the game using the
javacommand:java TicTacToe
-
Gameplay:
- Players take turns by entering the number corresponding to the grid position (1-9).
- The grid positions are as follows:
1x1 | 2x1 | 3x1 ---------------- 1x2 | 2x2 | 3x2 ---------------- 1x3 | 2x3 | 3x3 - The game continues until a player wins or the grid is full, resulting in a draw.
- The game starts with Player 1 ('X') and alternates between Player 1 and Player 2 ('O').
- Players select a cell (using a X|Y coordinate) to place their mark on the board.
- The first player to place three of their marks in a horizontal, vertical, or diagonal line wins.
- If all the grid positions are filled and no player has won, the game results in a draw.
Enjoy the game!