DEV Community

Sreeharsha
Sreeharsha

Posted on

First Post: Tic Tac Toe

Python Terminal Game: Tic Tac Toe

Tic Tac Toe is a classic game played on a 3x3 grid, where two players take turns marking X and O symbols in an attempt to get three of their symbols in a horizontal, vertical, or diagonal row. In this blog post, we'll explore a Python terminal game implementation of Tic Tac Toe.

Getting Started

To play the Tic Tac Toe game, you'll need to follow these steps:

  1. Clone the Repository: Start by cloning the Tic Tac Toe repository to your local machine using the following command:
   git clone https://github.com/sreeharsha-rav/python_projects.git
Enter fullscreen mode Exit fullscreen mode
  1. Run the Game: Navigate to the project directory and execute the Python script to start the game:
   python tic_tac_toe.py
Enter fullscreen mode Exit fullscreen mode

Game Features

Player Selection

At the beginning of each game, a random coin toss determines which player goes first. The players are represented by the symbols X and O. The game will display which player is starting the game.

Game Board

The game board is represented by a 3x3 grid, and each cell is numbered from 1 to 9. During their turns, players enter the corresponding number to mark their symbol on the grid. The game board is displayed after each player's move.

Win Condition

The game checks for a winning condition after each player's turn. If a player successfully forms a horizontal, vertical, or diagonal row with their symbols, they win the game. The winner's symbol is displayed, and their score is incremented.

Tie Condition

If no player manages to win the game and all cells on the game board are filled, the game ends in a tie. The number of draws is tracked, and a tie message is displayed.

Rematch Option

After a game ends, players have the option to play a rematch. Entering 'Y' restarts the game with a cleared game board, while entering 'N' quits the game.

Conclusion

The Python terminal game Tic Tac Toe provides an enjoyable gaming experience for two players. It demonstrates various programming concepts, such as class implementation, game logic, user input handling, and score tracking. Feel free to explore the code, customize the game, or use it as a starting point for your own Python projects.

To get started with Tic Tac Toe, visit the Tic Tac Toe repository. Have fun playing and mastering the game of Tic Tac Toe!

Happy coding!

Top comments (1)

Collapse
 
amedalen profile image
Aj

Thank you so much for this wonderful post, I got inspired and created Tic Tac Toe in rust with Webassembly

dev.to/amedalen/tic-tac-toe-in-rus...

Thank you.