# How can I make my Pygame Tic Tac Toe game better?

I have this code ready and it works just fine. But what are the ways by which I can improve this code? I have no CS background and this is my first coding project. I could not paste my entire code so I'm posting my github project link. Any recommendations on that would also be appreciated.

import pygame
pygame.init()

window = pygame.display.set_mode((600,600))

pygame.display.set_caption("Tic Tac Toe")
white = (255,255,255)
clicks = []

def Background():
window.fill(white)
pygame.draw.rect(window, (0,0,0),( 198,0,4,600))
pygame.draw.rect(window, (0,0,0),( 398,0,4,600))
pygame.draw.rect(window, (0,0,0),( 0,198,600,4))
pygame.draw.rect(window, (0,0,0),( 0,398,600,4))

pygame.display.flip()
run = True

while run:
pygame.time.delay(100)

for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False

mouse = pygame.mouse.get_pressed()[0]
mouse_x,mouse_y = pygame.mouse.get_pos()
if len(clicks)%2 != 0:
if mouse:
if mouse_x > 0 and mouse_x < 198 and mouse_y > 0 and mouse_y < 198:
clicks.append(mouse)

elif mouse_x > 0 and mouse_x < 198 and mouse_y > 202 and mouse_y < 398:
clicks.append(mouse)

elif mouse_x > 0 and mouse_x < 198 and mouse_y > 402 and mouse_y < 600:
clicks.append(mouse)

elif mouse_x > 202 and mouse_x < 398 and mouse_y > 0 and mouse_y < 198:
clicks.append(mouse)

elif mouse_x > 202 and mouse_x < 398 and mouse_y > 202 and mouse_y < 398:
clicks.append(mouse)

elif mouse_x > 202 and mouse_x < 398 and mouse_y > 402 and mouse_y < 600:
clicks.append(mouse)

elif mouse_x > 402 and mouse_x < 600 and mouse_y > 0 and mouse_y < 198:
clicks.append(mouse)

elif mouse_x > 402 and mouse_x < 600 and mouse_y > 202 and mouse_y < 398:
clicks.append(mouse)

elif mouse_x > 402 and mouse_x < 600 and mouse_y > 402 and mouse_y < 600:
clicks.append(mouse)

elif len(clicks)%2 == 0:
if mouse:
if mouse_x > 0 and mouse_x < 198 and mouse_y > 0 and mouse_y < 198:
clicks.append(mouse)

elif mouse_x > 0 and mouse_x < 198 and mouse_y > 202 and mouse_y < 398:
clicks.append(mouse)

elif mouse_x > 0 and mouse_x < 198 and mouse_y > 402 and mouse_y < 600:
clicks.append(mouse)

elif mouse_x > 202 and mouse_x < 398 and mouse_y > 0 and mouse_y < 198:
clicks.append(mouse)

elif mouse_x > 202 and mouse_x < 398 and mouse_y > 202 and mouse_y < 398:
clicks.append(mouse)

elif mouse_x > 202 and mouse_x < 398 and mouse_y > 402 and mouse_y < 600:
clicks.append(mouse)

elif mouse_x > 402 and mouse_x < 600 and mouse_y > 0 and mouse_y < 198:
clicks.append(mouse)

elif mouse_x > 402 and mouse_x < 600 and mouse_y > 202 and mouse_y < 398:
clicks.append(mouse)

elif mouse_x > 402 and mouse_x < 600 and mouse_y > 402 and mouse_y < 600:
clicks.append(mouse)
window.blit(Circle, (0,0))

window.blit(Circle, (0,201))

window.blit(Circle, (0,401))

window.blit(Circle, (201,0))

window.blit(Circle, (201,201))

window.blit(Circle, (201,401))

window.blit(Circle, (401,0))

window.blit(Circle, (401,201))

window.blit(Circle, (401,401))

window.blit(Cross, (0,0))

window.blit(Cross, (0,201))

window.blit(Cross, (0,401))

window.blit(Cross, (201,0))

window.blit(Cross, (201,201))

window.blit(Cross, (201,401))

window.blit(Cross, (401,0))

window.blit(Cross, (401,201))

window.blit(Cross, (401,401))

print("Circle Wins")

print("Cross Wins")

pygame.display.update()

Background()

pygame.quit()

• We cannot make recommendations or reviews of code behind a link. – dfhwze Jul 3 '19 at 4:31
• If you create variables var1, var2, and var3, it is about time to ask if you should do something different. In this case, you can consider using a list. – Pål GD Jul 3 '19 at 5:36
• Try to keep all functions (and while loops, for loops, if blocks, etc) to at most 30-50 lines. This is not a hard limit, but it makes life much easier if a block fits easily on screen. – Pål GD Jul 3 '19 at 5:37