This is a simple Tic Tac Toe game implemented in Java that runs in the terminal. Two players (X and O) take turns to place their marks on a 3x3 grid, and the game checks for win conditions after each move. The game also validates moves and announces the winner once the conditions are met.
- The game starts with an empty 3x3 board.
- Player X goes first, followed by Player O.
- Players take turns inputting the row and column numbers (0, 1, or 2) where they want to place their mark.
- The game checks for a winner after each move. The player who manages to align their marks (X or O) in a row, column, or diagonal wins.
- The game ends when a player wins or when all the cells on the board are filled (which results in a draw if there's no winner).
- Two-Player Game: Alternates between Player X and Player O.
- Win Detection: The game detects wins by checking rows, columns, and diagonals.
- Input Validation: Ensures that players can only place their marks on empty cells and within the grid limits.
- Draw Condition: The game continues until either a player wins or the board is full (resulting in a draw).
- Java 8 or later
-
Compile the Java file:
javac TicTacToe.java
-
Run the compiled Java file:
java TicTacToe
-
Follow the on-screen instructions to play the game.
Player X enter row and column: 0 0
X | |
---------
| |
---------
| |
Player O enter row and column: 1 1
X | |
---------
| O |
---------
| |
-
Winning: The game announces when a player wins by aligning their marks in a row, column, or diagonal.
Example:
Player X has won!
-
Draw: The game declares a draw if all cells are filled and no player has won:
It's a draw!
Thankyou for your time.