DEV Community

Sam
Sam

Posted on

A Simple Tic Tac Toe Terminal Game

https://github.com/SidertheCoder/Python-Git-Repository/blob/main/TTT.py

I am currently taking a computer science course on Codecademy.com and needed to make a terminal game for my portfolio project so I decided to make a game of Tic Tac Toe.

Image description

In my code I first created a dictionary to hold what would go in each box of the Tic Tac Toe board making use of the fact that the [ ] in a list looks like a box when printed in a terminal. I then use that dictionary in the function create_grid to present the board as it currently is. Next I made a class named Player that gets the 2 player names and also checks who is going first based on a roll randomized between 1 and 6, whoever is first also gets to pick if they want X or O. After that is a win_check function that checks if any of the 8 winning combinations appear on the grid. Finally a definition to initialize game and all previous functions plays and repeats players picking where their X or O goes until the board is full or a winning combination is found and prints out an announcement of the winner.

I am still quite new to Python so I'm aware I should've used comments more, remembered to commit more often and I could've made it look cleaner but I plan to continue to work so I can do those things better. Any tips or advice is always appreciated and thank you for reading.

Top comments (0)