
28.05.2024, 10:57
|
|
Познающий
Регистрация: 05.05.2022
Сообщений: 82
С нами:
2119802
Репутация:
8
|
|
Сообщение от tyukapa
Я чутка переделал код, надеюсь разберешься что и как там, если что-то непонятно, спрашивай
Python:
Код:
from
tkinter
import
*
root
=
Tk
(
)
root
.
title
(
"Tic Tac Toe"
)
frm
=
[
]
btn
=
[
]
who
=
True
playArea
=
[
0
]
*
9
def
reset
(
)
:
global
who
,
playArea
for
i
in
range
(
9
)
:
btn
[
i
]
.
config
(
text
=
' '
,
state
=
NORMAL
)
playArea
=
[
0
]
*
9
who
=
True
def
check_winner
(
)
:
for
i
in
range
(
3
)
:
if
playArea
[
i
*
3
]
==
playArea
[
i
*
3
+
1
]
==
playArea
[
i
*
3
+
2
]
!=
0
:
return
playArea
[
i
*
3
]
if
playArea
[
i
]
==
playArea
[
i
+
3
]
==
playArea
[
i
+
6
]
!=
0
:
return
playArea
[
i
]
if
playArea
[
0
]
==
playArea
[
4
]
==
playArea
[
8
]
!=
0
or
playArea
[
2
]
==
playArea
[
4
]
==
playArea
[
6
]
!=
0
:
return
playArea
[
4
]
return
0
def
play
(
n
)
:
global
who
btn
[
n
]
.
config
(
text
=
'X'
if
who
else
'0'
,
state
=
DISABLED
)
playArea
[
n
]
=
1
if
who
else
-
1
winner
=
check_winner
(
)
if
winner
!=
0
:
winner_text
=
'Player X has won!'
if
winner
==
1
else
'Player 0 has won!'
#1 строчка кода вместо 10+, не это ли счастье?
print
(
winner_text
)
message_label
.
config
(
text
=
winner_text
)
reset
(
)
elif
0
not
in
playArea
:
print
(
'Draw!'
)
message_label
.
config
(
text
=
'Draw!'
)
reset
(
)
else
:
who
=
not
who
for
i
in
range
(
3
)
:
frm
.
append
(
Frame
(
root
)
)
frm
[
i
]
.
pack
(
expand
=
YES
,
fill
=
BOTH
)
for
j
in
range
(
3
)
:
n
=
i
*
3
+
j
btn
.
append
(
Button
(
frm
[
i
]
,
text
=
' '
,
font
=
(
'mono'
,
20
,
'bold'
)
,
width
=
3
,
height
=
2
,
command
=
lambda
n
=
n
:
play
(
n
)
)
)
btn
[
n
]
.
pack
(
expand
=
YES
,
fill
=
BOTH
,
side
=
LEFT
,
padx
=
1
,
pady
=
1
)
message_label
=
Label
(
root
,
text
=
"Player X's turn"
,
font
=
(
'mono'
,
14
)
)
message_label
.
pack
(
side
=
TOP
,
pady
=
10
)
root
.
mainloop
(
)
О
Сообщение от tyukapa
Опять таки, работает, но не то что нужно. У меня у коде который был выше есть функции
Сообщение от tyukapa
def on_click(event):
print(f"Clicked at x={standings}")
moves =
array.append
g = (array[0])
desired_length = 5
def check_array_length(array, desired_length):
if len(array) > desired_length:
return True
else:
return False
if check_array_length(array, desired_length):
btn[g].config(text='', state=NORMAL)
array.pop(0)
Вот здесь она проверяет все ли крестики нолики израсходованы и если их больше 3 то они пропадают, а почему-то когда я переношу эти функции в твой она перестаёт работать либо ломается. Можешь помочь мне с этим ? Буду благодарен
|
|
|