import tkinter as tk from tkinter import messagebox class TicTacToe: def __init__(self, root): self.root = root self.root.title("Tic Tac Toe") self.current_player = "X" self.board = [[None for _ in range(3)] for _ in range(3)] self.buttons = [[None for _ in range(3)] for _ in range(3)] self.create_board() def create_board(self): """Oyunun tahtasını oluştur.""" for row in range(3): for col in range(3): button = tk.Button(self.root, text=" ", font=("Arial", 24), height=2, width=5, command=lambda r=row, c=col: self.make_move(r, c)) button.grid(row=row, column=col) self.buttons[row][col] = button def make_move(self, row, col): """Oyuncunun hamlesini işle.""" if self.board[row][col] is None: self.board[row][col] = self.current_player self.buttons[row][col].config(text=self.current_player) if self.check_winner(): messagebox.showinfo("Oyun Sonu", f"Oyuncu {self.current_player} kazandı!") self.reset_game() elif self.is_draw(): messagebox.showinfo("Oyun Sonu", "Oyun berabere!") self.reset_game() else: self.current_player = "O" if self.current_player == "X" else "X" def check_winner(self): """Kazananı kontrol et.""" for row in self.board: if row[0] == row[1] == row[2] and row[0] is not None: return True for col in range(3): if self.board[0][col] == self.board[1][col] == self.board[2][col] and self.board[0][col] is not None: return True if self.board[0][0] == self.board[1][1] == self.board[2][2] and self.board[0][0] is not None: return True if self.board[0][2] == self.board[1][1] == self.board[2][0] and self.board[0][2] is not None: return True return False def is_draw(self): """Beraberlik durumunu kontrol et.""" for row in self.board: if None in row: return False return True def reset_game(self): """Oyunu sıfırla.""" self.current_player = "X" self.board = [[None for _ in range(3)] for _ in range(3)] for row in range(3): for col in range(3): self.buttons[row][col].config(text=" ") # Tkinter uygulamasını başlat if __name__ == "__main__": root = tk.Tk() game = TicTacToe(root) root.mainloop()