![]() |
Tic Tac Toe victory - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Tic Tac Toe victory (/thread-36171.html) |
Tic Tac Toe victory - JustDarkWTF - Jan-24-2022 So i have been making slow progress on my tic tac toe im still missing some stuff bot I can do that by myself but I dont know how to make a victory. So I need some help with writing Victory if 3 rectangles or 3 O are connected. import tkinter canvas=tkinter.Canvas(width=700, height=700) canvas.pack() def board(): #definuje hraciu plochu canvas.create_line(50,150,350,150) canvas.create_line(150,50,150,350) canvas.create_line(250,50,250,350) canvas.create_line(50,250,350,250) canvas.create_rectangle(50,50,350,350) def get_coordinates (x, y): #zistí polohu kliknutia a položí dany predmet do stredu štvorca if x > 49 and x < 350 and y > 49 and y < 350 : x = ((x - 150) // 100 * 100) + 170 y = ((y - 150) // 100 * 100) + 170 return x, y else : return 0, 0#ak sa klikne mimo hracej plochy tak nevykreslí nič def kruh(sur): x, y = get_coordinates (sur.x, sur.y) if x > 0 : canvas.create_oval(x,y,x+60,y+60, fill='blue') def stvorec(sur): x, y = get_coordinates (sur.x, sur.y) if x > 0 : canvas.create_rectangle(x,y,x+60,y+60,fill='red') def resetAll(): canvas.delete('all') board() def start(): canvas.delete('all') canvas.bind('<Button-3>', stvorec) canvas.bind('<Button-1>', kruh) board() reset=tkinter.Button(text='RESET', command=resetAll) reset.pack() start.pack_forget() start=tkinter.Button(text='START', command=start) start.pack() RE: Tic Tac Toe victory - deanhystad - Jan-24-2022 To identify a winner you need to record what markers are in what spots. If you have that it is easy to identify a winning move because there are only 8 winning board combinations; 3 rows, 3 columns, 2 diagonals. |