Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please generate the release apk file. Thank you #41

Open
sanrenjieba opened this issue Feb 13, 2024 · 2 comments
Open

Please generate the release apk file. Thank you #41

sanrenjieba opened this issue Feb 13, 2024 · 2 comments

Comments

@sanrenjieba
Copy link

屏幕截图 2024-02-13 222603

@amirali0890
Copy link

self.current_player = "♤"
self.board = [" " for _ in range(9)]

self.buttons = []
for i in range(9):
    row, col = divmod(i, 3)
    button = tk.Button(root, text=" ", font=("Helvetica", 24), width=5, height=2,
                       command=lambda i=i: self.on_click(i))
    button.grid(row=row, column=col)
    self.buttons.append(button)

def on_click(self, index):
if self.board[index] == " ":
self.board[index] = self.current_player
self.buttons[index].config(text=self.current_player)
if self.check_winner():
messagebox.showinfo("Game Over", f"Player {self.current_player} wins!")
self.reset_game()
elif " " not in self.board:
messagebox.showinfo("Game Over", "It's a draw!")
self.reset_game()
else:
self.current_player = "♤" if self.current_player == "♡" else "♡"

def check_winner(self):
win_patterns = [(0, 1, 2), (3, 4, 5), (6, 7, 8),
(0, 3, 6), (1, 4, 7), (2, 5, 8),
(0, 4, 8), (2, 4, 6)]

for pattern in win_patterns:
    if self.board[pattern[0]] == self.board[pattern[1]] == self.board[pattern[2]] != " ":
        return True
return False

def reset_game(self):
self.board = [" " for _ in range(9)]
for button in self.buttons:
button.config(text=" ")
self.current_player = "♤"

@Limour-dev
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants