-
Notifications
You must be signed in to change notification settings - Fork 0
/
bingo_function.py
45 lines (37 loc) · 1.74 KB
/
bingo_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from tkinter import messagebox
score=0
def change_color(button):
button.config(bg="green", fg="red")
check_win()
# function to check for a win
def check_win(row_score, column_score, diagonal_score, row_completed, column_completed, left_diagonal_completed, right_diagonal_completed,buttons):
global score
# check rows
for i in range(5):
if not row_completed[i] and all(buttons[i*5 + j].cget('bg') == 'green' for j in range(5)):
print("Row win!")
score += 1
row_score += 1
row_completed[i] = True
# Check for column win
for j in range(5):
if not column_completed[j] and all(buttons[i*5 + j].cget('bg') == 'green' for i in range(5)):
print("Column win!")
score += 1
column_score += 1
column_completed[j] = True
# Check for left diagonal win
if not left_diagonal_completed and all(buttons[i*5 + i].cget('bg') == 'green' for i in range(5)):
print("Left diagonal win!")
diagonal_score += 1
left_diagonal_completed = True
# Check for right diagonal win
if not right_diagonal_completed and all(buttons[i*5 + (4-i)].cget('bg') == 'green' for i in range(5)):
print("Right diagonal win!")
diagonal_score += 1
right_diagonal_completed = True
#print(f"Row Score: {row_score}, Column Score: {column_score}, Diagonal Score: {diagonal_score},Score: {score}, sum:{score+diagonal_score}")
if score + diagonal_score == 5:
print("BINGO!")
messagebox.showinfo("BINGO","BINGO\nCongratulations! You've won the game!")
# return row_score, column_score, diagonal_score, row_completed, column_completed, left_diagonal_completed, right_diagonal_completed