A Simple Tic Tac Toe Terminal Game

DDD
Release: 2024-10-30 04:20:28
Original
732 people have browsed it

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.

A Simple Tic Tac Toe Terminal Game

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.

The above is the detailed content of A Simple Tic Tac Toe Terminal Game. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template