Dec-26-2020, 01:51 PM
I somehow created Tic tac toe (not finished yet). when I place 'X' it place 'X' properly, and when I place 'O' it place 'O' but it also change 'X' to 'O' and then it continue to change.
import pygame import random pygame.init() #Window dimention width = 600 hight = 600 #color black = (0, 0, 0) white = (250, 250, 250) #block and line position and variables mouse_pos = (700,700) linex1 = 200 linex2 = 400 liney1 = 200 liney2 = 400 block1 = False block2 = False block3 = False block4 = False block5 = False block6 = False block7 = False block8 = False block9 = False display = pygame.display.set_mode((width, hight)) num = 1 def draw(x_pos, y_pos): global num if num % 2 == 0: pygame.draw.circle(display, black, (x_pos, y_pos), 75, 15) num += 1 elif num % 2 != 0: a = x_pos + 70 b = y_pos - 70 c = x_pos - 70 d = y_pos + 70 pygame.draw.line(display, black, (a, b), (c, d), 15) a = x_pos - 70 b = y_pos - 70 c = x_pos + 70 d = y_pos + 70 pygame.draw.line(display, black, (a, b), (c, d), 15) num += 1 game_over = False while not game_over: for event in pygame.event.get(): if event.type == pygame.QUIT: game_over = True if event.type == pygame.MOUSEBUTTONUP: #to get mouse positon when click mouse_pos = pygame.mouse.get_pos() if mouse_pos[0] <= linex1 and mouse_pos[1] <= liney1: print('Block 1') block1 = True elif mouse_pos[0] >= linex1 and mouse_pos[0] <= linex2 and mouse_pos[1] <= liney1: print('Block 2') block2 = True elif mouse_pos[0] >= linex2 and mouse_pos[1] <= liney1: print('Block 3') block3 = True elif mouse_pos[0] <= linex1 and mouse_pos[1] >= liney1 and mouse_pos[1] <= liney2: print('Block 4') block4 = True elif mouse_pos[0] >= linex1 and mouse_pos[1] >= liney1 and mouse_pos[0] <= linex2 and mouse_pos[1] <= liney2: print('Block 5') block5 = True elif mouse_pos[0] >= linex2 and mouse_pos[1] >= liney1 and mouse_pos[1] <= liney2: print('Block 6') block6 = True elif mouse_pos[0] <= linex1 and mouse_pos[1] >= liney2: print('Block 7') block7 = True elif mouse_pos[0] >= linex1 and mouse_pos[1] >= liney2 and mouse_pos[0] <= linex2: print('Block 8') block8 = True elif mouse_pos[0] >= linex2 and mouse_pos[1] >= liney2: print('Block 9') block9 = True display.fill(white) #lines line1 = pygame.draw.line(display, black, (200, 0), (200, 600), 2) line4 = pygame.draw.line(display, black, (400, 0), (400, 600), 2) line3 = pygame.draw.line(display, black, (0, 200), (600, 200), 2) line4 = pygame.draw.line(display, black, (0, 400), (600, 400), 2) if block1 == True: draw(100, 100) if block2 == True: draw(300, 100) if block3 == True: draw(500, 100) if block4 == True: draw(100, 300) if block5 == True: draw(300, 300) if block6 == True: draw(500, 300) if block7 == True: draw(100, 500) if block8 == True: draw(300, 500) if block9 == True: draw(500, 500) pygame.display.update() pygame.quit() quit()I'm not able to interpret what is issue but if you run this code you will know. does anyone know how to fix this problem