#!/usr/bin/python3.4
import tkinter as tk
import time
import os
root = tk.Tk()
label = tk.Label(root)
root.configure(background='#0C142E')
ButtonTable=[]
Turn = 0 # 0(x) 1(O)
XO=["X","O"]
wins = [
'111 000 000', '000 111 000', '000 000 111', # Across
'100 100 100', '010 010 010', '001 001 001', # Down
'100 010 001', '001 010 100', # Diagonal
]
GridArray=["","","","","","","","","",] # Gets replaced with x,o to record progress
def CheckWin():
#something goes here?
def CreateButtonmid(Text,side, Return):
return CreateButton
def ChooseButton(xx,b):
global Turn
b.configure(state = "disabled")
print(xx)
b.config(text=XO[Turn])
GridArray[int(xx)]=XO[Turn]
CheckWon()
if Turn == 0:
Turn = 1
else:
Turn=0
label.configure(text="Turn: "+XO[Turn])
print(GridArray)
def CreateButton(Text,side,Return):
b = tk.Button(side,text=Text)
b.pack(side="left")
b.config(command=lambda: ChooseButton(Return,b))
ButtonTable.append(b)
b.configure(background='#323642',bd=0,fg="white",height=5,width=10)
return b
label.pack(side = "top")
label.config(bg="#0C142E",fg="#fff",text="(STARTING:X)")
topframe = tk.Frame(root)
topframe.pack(side = "top")
CreateButton("[]",topframe,("0"))
CreateButton("[]",topframe,("1"))
CreateButton("[]",topframe,("2"))
midframe = tk.Frame(root)
midframe.pack(side = "top")
CreateButton("[]",midframe,("3"))
CreateButton("[]",midframe,("4"))
CreateButton("[]",midframe,("5"))
bottomframe = tk.Frame(root)
bottomframe.pack(side = "top")
CreateButton("[]",bottomframe,("6"))
CreateButton("[]",bottomframe,("7"))
CreateButton("[]",bottomframe,("8"))
root.mainloop()
基本上它是一個多人遊戲,需要兩個人玩。什麼是檢查是否有人獲勝的最好方法。我不知道,我是新來編程,任何資源,以幫助這個或我的編碼隨時歡迎Python編程3.4.2,Naughts and Crosses。檢查如何查看遊戲是否獲勝的最佳方法?
井字棋== Naughts翻山 –
這取決於你是從哪裏來的。 –
我沒有糾正你。我試圖幫助其他讀者(可能是不必要的)。 –