This is a Python Terminal Game that was part of a Portfolio Project for the Computer Science Codecademy course.
The source code can be found on Github using the following link: https://github.com/IoanPapuc/tic_tac_toe_terminal_game-.git
Description and Functionalities
The presented program, written in Python, generates a terminal version of the Tic Tac Toe game, also known as Xs and Os, which can be played by two users.
The players are asked successively to input the location, consisting of row and column, where they want their specific character to be inserted. Every time a user enters a new symbol, the grid is updated and displayed into the terminal.
Errors generated by the introduction of non-valid inputs are identified and treated accordingly: the user is asked to re-enter a row and a column if the entered values are integers different from 1, 2 or 3 or if the respective location has been previously filled. The same thing happens if non-integer data types are entered instead of a row or column. The only exception to the last rule is made for the character 'Q' which can be entered by any player to quit the current game.
The game ends when a player first satisfies one of the three winning conditions, when a draw is reached or when one of the player uses the 'Q' option.
Users have the possibility to play multiple games in a row without running the source code from the file each time, due to a menu-managed game framework that has been set. The menu provides two options: 'S' to start a game and 'E' to exit the program.
Short Overview of the functions
new_board() - creates a new empty grid
print_board() - displays the grid in a suitable manner
insert_symbol(board, symbol) - asks the users to input the row and column of their own character and updates the grid accordingly before printing it; also checks and ensures the accuracy in data entry
full_row(board, symbol), full_column(board, symbol), full_diag(board, symbol) - return 'True' if a sequence of three identical symbols are placed in a row, column or diagonal
winning_verification(board, symbol) - returns 'True' if one of the three winning criteria from above is satisfied
play_game() - the main function in the program; includes all of the previously mentioned function and establishes the conditions for stopping the game
game_menu() - very simple menu-driven interface created to make multi-game sessions easier to play
Obviously, this is just a basic version of the classic Tic Tac Toe game. It can be improved and completed in countless ways such that, with enough imagination, can lead to a sufficiently complex and challenging game.
Top comments (0)