This is a simple implementation of the classic Tic Tac Toe game in Java. The game is played on a 3x3 grid and is designed for two players, X and O.
- Two-player game
- Simple text-based user interface
- Checks for win conditions and draws
- Clone the repository:
git clone https://github.com/Aamod007/tictactoe-java.git
- Navigate to the project directory:
cd tictactoe-java - Compile the Java program:
javac TTT.java
- Run the Java program:
java TTT
- The game will prompt the first player (X) to enter a slot number to place their marker.
- Players take turns entering a slot number to place their marker (X or O) on the board.
- The game will display the board after each move.
- The game checks for win conditions after each turn.
- If a player wins, a congratulatory message is displayed.
- If all slots are filled and there is no winner, the game declares a draw.
Welcome to 3x3 Tic Tac Toe. |---|---|---| | 1 | 2 | 3 | |-----------| | 4 | 5 | 6 | |-----------|
7 8 9 X will play first. Enter a slot number to place X in: 1
7 8 9 O's turn; enter a slot number to place O in: 5
7 8 9
TTTclass: Contains the main method and game logic.checkWinnermethod: Checks for winning conditions and declares the winner or a draw.printBoardmethod: Prints the current state of the board.mainmethod: Initializes the game, handles user input, and controls the game flow.
Feel free to fork this repository and contribute by submitting pull requests. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License.