浔川官方在浔川AI五子棋v1.4的基础上,改变了画布、选项等,为广大五子棋爱好者提供最方便的游戏体验。
正式代码:
import tkinter.messagebox
window.title('AI五子棋登录界面')
window.geometry('450x200')
Verification_Code = random.randint(1000, 9999)
Verification_Code = str(Verification_Code)
print(type(Verification_Code))
tk.Label(window, text='用户名:').place(x=100, y=30)
tk.Label(window, text='密码:').place(x=100, y=70)
tk.Label(window, text='验证码').place(x=100, y=110)
tk.Label(window, text=Verification_Code).place(x=320, y=110)
var_usr_name = tk.StringVar()
entry_usr_name = tk.Entry(window, textvariable=var_usr_name)
entry_usr_name.place(x=160, y=30)
var_usr_pwd = tk.StringVar()
entry_usr_pwd = tk.Entry(window, textvariable=var_usr_pwd, show='*')
entry_usr_pwd.place(x=160, y=70)
var_usr_yzm = tk.StringVar()
entry_usr_yzm = tk.Entry(window, textvariable=var_usr_yzm)
entry_usr_yzm.place(x=160, y=110)
usr_name = var_usr_name.get()
usr_pwd = var_usr_pwd.get()
usr_yzm = var_usr_yzm.get()
print(type(usr_yzm),type(Verification_Code))
with open('usr_info.pickle', 'rb') as usr_file:
usrs_info = pickle.load(usr_file)
except FileNotFoundError:
with open('usr_info.pickle', 'wb') as usr_file:
usrs_info = {'admin': 'admin'}
pickle.dump(usrs_info, usr_file)
if usr_yzm == Verification_Code:
if usr_name in usrs_info:
if usr_pwd == usrs_info[usr_name]:
tk.messagebox.showinfo(title='welcome',
message='欢迎您:' + usr_name)
tk.messagebox.showerror(message='密码错误')
elif usr_name == '' or usr_pwd == '':
tk.messagebox.showerror(message='用户名或密码为空')
is_signup = tk.messagebox.askyesno('欢迎', '您还没有注册,是否现在注册')
tk.messagebox.showerror(message='验证码不能为空')
tk.messagebox.showerror(message='验证码有误!')
npf = new_pwd_confirm.get()
with open('usr_info.pickle', 'rb') as usr_file:
exist_usr_info = pickle.load(usr_file)
except FileNotFoundError:
tk.messagebox.showerror('错误', '用户名已存在')
elif np == '' or nn == '':
tk.messagebox.showerror('错误', '用户名或密码为空')
tk.messagebox.showerror('错误', '密码前后不一致')
with open('usr_info.pickle', 'wb') as usr_file:
pickle.dump(exist_usr_info, usr_file)
tk.messagebox.showinfo('欢迎', '注册成功')
window_sign_up = tk.Toplevel(window)
window_sign_up.geometry('350x200')
window_sign_up.title('注册')
new_name = tk.StringVar()
tk.Label(window_sign_up, text='用户名:').place(x=10, y=10)
tk.Entry(window_sign_up, textvariable=new_name).place(x=150, y=10)
tk.Label(window_sign_up, text='请输入密码:').place(x=10, y=50)
tk.Entry(window_sign_up, textvariable=new_pwd, show='*').place(x=150, y=50)
new_pwd_confirm = tk.StringVar()
tk.Label(window_sign_up, text='请再次输入密码:').place(x=10, y=90)
tk.Entry(window_sign_up, textvariable=new_pwd_confirm, show='*').place(x=150, y=90)
bt_confirm_sign_up = tk.Button(window_sign_up, text='确认注册',
bt_confirm_sign_up.place(x=150, y=130)
bt_login = tk.Button(window, text='登录', command=usr_log_in)
bt_login.place(x=140, y=150)
bt_logup = tk.Button(window, text='注册', command=usr_sign_up)
bt_logup.place(x=210, y=150)
bt_logquit = tk.Button(window, text='退出', command=usr_sign_quit)
bt_logquit.place(x=280, y=150)
window.geometry('630x150')
tk.Label(window, text='下载进度:', ).place(x=50, y=60)
canvas = tk.Canvas(window, width=465, height=22, bg="white")
canvas.place(x=110, y=60)
fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="green")
canvas.coords(fill_line, (0, 0, n, 60))
fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="white")
canvas.coords(fill_line, (0, 0, n, 60))
btn_download = tk.Button(window, text='开始下载', command=progress)
btn_download.place(x=400, y=105)
window.geometry('630x150')
tk.Label(window, text='安装进度:', ).place(x=50, y=60)
canvas = tk.Canvas(window, width=465, height=22, bg="white")
canvas.place(x=110, y=60)
fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="green")
canvas.coords(fill_line, (0, 0, n, 60))
fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="white")
canvas.coords(fill_line, (0, 0, n, 60))
btn_download = tk.Button(window, text='开始安装', command=progress)
btn_download.place(x=400, y=105)
self.window.title("五子棋游戏")
self.window.geometry("660x470")
self.window.resizable(0,0)
self.canvas=Canvas(self.window , bg="#EEE8AC" , width=470, height=470)
self.canvas.grid(row = 0 , column = 0)
if row == 0 or row == 14 :
self.canvas.create_line(25 , 25+row*30 , 25+14*30 , 25+row*30 , width = 2)
self.canvas.create_line(25 , 25+row*30 , 25+14*30 , 25+row*30 , width = 1)
for column in range(0,15) :
if column == 0 or column == 14 :
self.canvas.create_line(25+column*30 ,25, 25+column*30 , 25+14*30 ,width = 2)
self.canvas.create_line(25+column*30 ,25, 25+column*30 , 25+14*30 , width = 1)
self.canvas.create_oval(112, 112, 118, 118, fill="black")
self.canvas.create_oval(352, 112, 358, 118, fill="black")
self.canvas.create_oval(112, 352, 118, 358, fill="black")
self.canvas.create_oval(232, 232, 238, 238, fill="black")
self.canvas.create_oval(352, 352, 358, 358, fill="black")
self.board = chessBoard()
self.game_print = StringVar()
self.db = [([2] * 16) for i in range(16)]
self.color_count = (self.color_count + 1 ) % 2
if self.color_count == 0 :
elif self.color_count ==1 :
def chess_moving(self ,event) :
if self.flag_win ==1 or self.flag_empty ==0 :
x,y = event.x-25 , event.y-25
while self.db[y][x] == 2 and self.limit_boarder(y,x):
self.db[y][x] = self.color_count
self.order.append(x+15*y)
self.board.canvas.create_oval(25+30*x-12 , 25+30*y-12 , 25+30*x+12 , 25+30*y+12 , fill = self.color,tags = "chessman")
if self.game_win(y,x,self.color_count) :
self.game_print.set(self.color+"获胜")
self.game_print.set("请"+self.color+"落子")
def limit_boarder(self , y , x) :
if x<0 or x>14 or y<0 or y>14 :
def chessman_count(self , y , x , color_count ) :
count1,count2,count3,count4 = 1,1,1,1
for i in range(-1 , -5 , -1) :
if self.db[y][x+i] == color_count :
for i in range(1 , 5 ,1 ) :
if self.db[y][x+i] == color_count :
for i in range(-1 , -5 , -1) :
if self.db[y+i][x] == color_count :
for i in range(1 , 5 ,1 ) :
if self.db[y+i][x] == color_count :
for i in range(-1 , -5 , -1) :
if self.db[y+i][x+i] == color_count :
for i in range(1 , 5 ,1 ) :
if self.db[y+i][x+i] == color_count :
for i in range(-1 , -5 , -1) :
if self.db[y+i][x-i] == color_count :
for i in range(1 , 5 ,1 ) :
if self.db[y+i][x-i] == color_count :
return max(count1 , count2 , count3 , count4)
def game_win(self , y , x , color_count ) :
if self.chessman_count(y,x,color_count) >= 5 :
if len(self.order)==0 or self.flag_win == 1:
self.board.canvas.delete("chessman")
self.board.canvas.create_oval(25+30*ix-12 , 25+30*iy-12 , 25+30*ix+12 , 25+30*iy+12 , fill = self.color,tags = "chessman")
self.game_print.set("请"+self.color+"落子")
self.board.canvas.delete("chessman")
self.db = [([2] * 16) for i in range(16)]
self.game_print.set("请"+self.color+"落子")
self.board.canvas.bind("",self.chess_moving)
Label(self.board.window , textvariable = self.game_print , font = ("Arial", 20) ).place(relx = 0, rely = 0 ,x = 495 , y = 200)
Button(self.board.window , text= "开始游戏" ,command = self.game_start,width = 13, font = ("Verdana", 12)).place(relx=0, rely=0, x=495, y=15)
Button(self.board.window , text= "我要悔棋" ,command = self.withdraw,width = 13, font = ("Verdana", 12)).place(relx=0, rely=0, x=495, y=60)
Button(self.board.window , text= "清空棋局" ,command = self.empty_all,width = 13, font = ("Verdana", 12)).place(relx=0, rely=0, x=495, y=105)
Button(self.board.window , text= "结束游戏" ,command = self.board.window.destroy,width = 13, font = ("Verdana", 12)).place(relx=0, rely=0, x=495, y=420)
self.board.window.mainloop()
if __name__ == "__main__":
使用步骤:
1:登录浔川AI五子棋
2:下载浔川AI五子棋
3:安装浔川AI五子棋
4:进入五子棋游戏(双人)