@@ -54,6 +54,10 @@ def check_winner():
5454 buttons [combo [1 ][0 ]][combo [1 ][1 ]]["text" ] == \
5555 buttons [combo [2 ][0 ]][combo [2 ][1 ]]["text" ] != " " :
5656
57+ # ✅ Highlight winning cells
58+ for pos in combo :
59+ buttons [pos [0 ]][pos [1 ]].config (bg = "green" )
60+
5761 winner_symbol = buttons [combo [0 ][0 ]][combo [0 ][1 ]]["text" ]
5862
5963 if winner_symbol == "X" :
@@ -75,27 +79,29 @@ def button_click(row, col):
7579 if buttons [row ][col ]["text" ] == " " :
7680 buttons [row ][col ]["text" ] = current_player
7781
78- # ✅ YOUR FEATURE ( Move History)
82+ # ✅ Move History
7983 player = p1 .get () if current_player == "X" else p2 .get ()
8084 player = player or ("Player 1" if current_player == "X" else "Player 2" )
8185
8286 move = f"{ move_number } . { player } -> ({ row + 1 } ,{ col + 1 } )"
8387 history_box .insert (END , move + "\n " )
8488
8589 move_number += 1
86-
87- # ✅ GAME LOGIC
8890 moves_count += 1
8991
9092 if check_winner ():
9193 return
9294
9395 if moves_count == 9 :
9496 messagebox .showinfo ("Tie" , "It's a Tie!" )
97+ disable_buttons () # ✅ prevent extra clicks
9598 return
9699
97100 current_player = "O" if current_player == "X" else "X"
98101
102+ else :
103+ messagebox .showinfo ("Invalid Move" , "Button already clicked!" )
104+
99105def reset_game ():
100106 global current_player , moves_count , move_number
101107
@@ -107,9 +113,9 @@ def reset_game():
107113
108114 for i in range (3 ):
109115 for j in range (3 ):
110- buttons [i ][j ].config (text = " " , state = NORMAL )
116+ buttons [i ][j ].config (text = " " , bg = "black" , state = NORMAL )
111117
112- # Create buttons
118+ # Create buttons (safe version)
113119for i in range (3 ):
114120 for j in range (3 ):
115121 buttons [i ][j ] = Button (
0 commit comments