From 225aaebe67e20e571f83b6db43b4c1774ee4dd4e Mon Sep 17 00:00:00 2001 From: AnishKr91620 <145275076+AnishKr91620@users.noreply.github.com> Date: Sun, 15 Oct 2023 10:29:50 +0530 Subject: [PATCH] Create tic-tac-toe-gui-in-python-using-pygame MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This article will guide you and give you a basic idea of designing a game Tic Tac Toe using pygame library of Python. Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Let’s break the task in five parts: Importing the required libraries and setting up the required global variables. Designing the game display function, that will set a platform for other components to be displayed on the screen. Main algorithm of win and draw Getting the user input and displaying the “X” or “O” at the proper position where the user has clicked his mouse. Running an infinite loop, and including the defined methods in it. --- tic-tac-toe-gui-in-python-using-pygame | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tic-tac-toe-gui-in-python-using-pygame diff --git a/tic-tac-toe-gui-in-python-using-pygame b/tic-tac-toe-gui-in-python-using-pygame new file mode 100644 index 00000000..9064c394 --- /dev/null +++ b/tic-tac-toe-gui-in-python-using-pygame @@ -0,0 +1,36 @@ +# importing the required libraries +import pygame as pg +import sys +import time +from pygame.locals import * + +# declaring the global variables + +# for storing the 'x' or 'o' +# value as character +XO = 'x' + +# storing the winner's value at +# any instant of code +winner = None + +# to check if the game is a draw +draw = None + +# to set width of the game window +width = 400 + +# to set height of the game window +height = 400 + +# to set background color of the +# game window +white = (255, 255, 255) + +# color of the straightlines on that +# white game board, dividing board +# into 9 parts +line_color = (0, 0, 0) + +# setting up a 3 * 3 board in canvas +board = [[None]*3, [None]*3, [None]*3]