1.井字棋
注意,这个不是人工,需要两个人对战。
from tkinter import *
import tkinter.messagebox as msg
root = Tk()
root.title('TIC-TAC-TOE---Project Gurukul')
# labels
Label(root, text="player1 : X", font="times 15").grid(row=0, column=1)
Label(root, text="player2 : O", font="times 15").grid(row=0, column=2)
digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]
# for player1 sign = X and for player2 sign= Y
mark = ''
# counting the no. of click
count = 0
panels = ["panel"] * 10
def win(panels, sign):
return ((panels[1] == panels[2] == panels[3] == sign)
or (panels[1] == panels[4] == panels[7] == sign)
or (panels[1] == panels[5] == panels[9] == sign)
or (panels[2] == panels[5] == panels[8] == sign)
or (panels[3] == panels[6] == panels[9] == sign)
or (panels[3] == panels[5] == panels[7] == sign)
or (panels[4] == panels[5] == panels[6] == sign)
or (panels[7] == panels[8] == panels[9] == sign))
def checker(digit):
global count, mark, digits
# Check which button clicked
if digit == 1 and digit in digits:
digits.remove(digit)
##player1 will play if the value of count is even and for odd player2 will play
if count % 2 == 0:
mark = 'X'
panels[digit] = mark
elif count % 2 != 0:
mark = 'O'
panels[digit] = mark
button1.config(text=mark)
co