Игра в бинго работает хорошо
БИНГО ИГРА
Проблема в том, что все работает нормально, но когда 5 строк заполнены
то есть BINGO, но он позволяет кликать по другому номеру.
Может быть какая-то логическая ошибка, из-за которой он работает следующим образом.
Мне нужен один игрок, который нажимает на эту доску, если он щелкает пять строк, столбцов или перекрестных чисел, тогда БИНГО
В каждый момент времени строка или столбец или крестик Каждая буква слова БИНГО показывает
from tkinter import *
from random import *
tk = Tk()
head = Frame(tk)
head.pack()
l = Label(head, text="BINGO", font=('Times 30 bold'))
l.pack()
main = Frame(tk)
main.pack()
curr = []
while len(curr) != 25:
x = randint(1, 25)
if x in curr:
pass
else:
curr.append(x)
print(curr)
print(len(curr))
def textv(i):
r.set(curr[i])
return
r = StringVar()
checked = []
dic = []
count = 0
var = StringVar()
label = Label(tk, textvariable=var, relief=RAISED)
label.pack()
w = ('B', 'I', 'N', 'G', 'O')
m = ('B', 'I', 'N', 'G', 'O')
l = []
def win():
global count
try:
l.append(w[count])
var.set(l)
print(var.get())
print(str(l))
count += 1
if w == var.get():
print("yse")
else:
print("no")
except:
print("BINGO")
return
num_of_flag = 12
flag = []
for i in range(num_of_flag):
flag.append(False)
print(flag)
def is_bingo():
if flag[0] == False and input[0]["background"] == input[1]["background"] == input[2]["background"] == input[3]["background"] == input[4]["background"] == "red":
win()
flag[0] = True
elif flag[1] == False and input[5]["background"] == input[6]["background"] == input[7]["background"] == input[8]["background"] == input[9]["background"] == "red":
win()
flag[1] = True
elif flag[2] == False and input[10]["background"] == input[11]["background"] == input[12]["background"] == input[13]["background"] == input[14]["background"] == "red":
win()
flag[2] = True
elif flag[3] == False and input[15]["background"] == input[16]["background"] == input[17]["background"] == input[18]["background"] == input[19]["background"] == "red":
win()
flag[3] = True
elif flag[4] == False and input[20]["background"] == input[21]["background"] == input[22]["background"] == input[23]["background"] == input[24]["background"] == "red":
win()
flag[4] = True
elif flag[5] == False and input[0]["background"] == input[5]["background"] == input[10]["background"] == input[15]["background"] == input[20]["background"] == "red":
win()
flag[5] = True
elif flag[6] == False and input[1]["background"] == input[6]["background"] == input[11]["background"] == input[16]["background"] == input[21]["background"] == "red":
win()
flag[6] = True
elif flag[7] == False and input[2]["background"] == input[7]["background"] == input[12]["background"] == input[17]["background"] == input[22]["background"] == "red":
win()
flag[7] = True
elif flag[8] == False and input[3]["background"] == input[8]["background"] == input[13]["background"] == input[18]["background"] == input[23]["background"] == "red":
win()
flag[8] = True
elif flag[9] == False and input[4]["background"] == input[9]["background"] == input[14]["background"] == input[19]["background"] == input[24]["background"] == "red":
win()
flag[9] = True
elif flag[10] == False and input[0]["background"] == input[6]["background"] == input[12]["background"] == input[18]["background"] == input[24]["background"] == "red":
win()
flag[10] = True
elif flag[11] == False and input[4]["background"] == input[8]["background"] == input[12]["background"] == input[16]["background"] == input[20]["background"] == "red":
win()
flag[11] = True
def bingo(btn, i):
btn["background"] = "red"
is_bingo()
input = []
n = 25
for i in range(n):
input.append(Button(main, font=('Times 20 bold'), bg='white', fg='black', height=2, width=4))
row = 3
column = 0
index = 1
k = 0
for i in range(5):
for j in range(5):
input[k].grid(row=row, column=column)
input[k]["text"] = curr[k]
input[k].config(command=lambda current_button=input[k], index_value=k, row_value=i, column_value=j: bingo(current_button, index_value))
column += 1
if index % 6 == 0:
row += 1
column = 0
index += 1.
k += 1
row = 1
column = 0
index = 1
for i in range(len(input)):
input[i].config(textvariable=curr[i])
input[i].grid(row=row, column=column)
column += 1
if index % 5 == 0:
row += 1
column = 0
index += 1
tk.mainloop()