You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
4.9 KiB
104 lines
4.9 KiB
from PIL import Image, ImageTk
|
|
from tkinter import *
|
|
|
|
local = True
|
|
# local = False
|
|
if local == True:
|
|
path = ""
|
|
else:
|
|
path = "/data/workspace/myshixun/finalchess/"
|
|
|
|
|
|
# 绘制棋盘
|
|
def cross(canvas):
|
|
for i in range(19): # 横线
|
|
point = [[40, 37], [706, 37]]
|
|
point[0][1] = 21 + i*34.3
|
|
point[1][1] = 21 + i*34.3
|
|
if i == 0 or i == 18:
|
|
canvas.create_line(point, fill="#C18B5F", width=2.5)
|
|
canvas.create_line(point, fill="#C18B5F", width=1.5)
|
|
for i in range(19): # 竖线
|
|
point = [[41, 21], [41, 640]]
|
|
point[0][0] = 41 + i*37
|
|
point[1][0] = 41 + i*37
|
|
if i == 0 or i == 18:
|
|
canvas.create_line(point, fill="#C18B5F", width=2.5)
|
|
canvas.create_line(point, fill="#C18B5F", width=1.5)
|
|
for x in (4, 9, 14):
|
|
for y in (4, 9, 14):
|
|
if x == y == 9:
|
|
radius = 9
|
|
else:
|
|
radius = 6
|
|
canvas.create_oval(x*36.9 + 41 - radius / 2,
|
|
y*34.3 + 21 - radius / 2,
|
|
x*36.9 + 41 + radius / 2,
|
|
y*34.3 + 21 + radius / 2,
|
|
fill='#BE875E', outline="")
|
|
|
|
# 画棋子
|
|
def drawChess(canvas, pos, chess):
|
|
for i in pos:
|
|
if chess.chessData[i[0]][i[1]]['Cstate'] == 0 and (i[0] != 0 and i[1] != 0):
|
|
if chess.myColor == 1 and chess.player2Color == 2:
|
|
Ovalone = canvas.create_oval(i[0] * 36.8 + 41 - 12.5, i[1] * 34.6 + 21 - 13.5,
|
|
i[0] * 36.8 + 41 + 12.5, i[1] * 34.6 + 21 + 13.5,
|
|
fill='#fff', outline="#000")
|
|
elif chess.myColor == 2 and chess.player2Color == 1:
|
|
Ovalone = canvas.create_oval(i[0] * 36.8 + 41 - 12.5, i[1] * 34.6 + 21 - 13.5,
|
|
i[0] * 36.8 + 41 + 12.5, i[1] * 34.6 + 21 + 13.5,
|
|
fill='#000', outline="#fff")
|
|
elif chess.myColor == 2 and chess.player2Color == 1:
|
|
if chess.player == 1 and chess.player2 == 0:
|
|
Ovalone = canvas.create_oval(i[0] * 36.8 + 41 - 12.5, i[1] * 34.6 + 21 - 13.5,
|
|
i[0] * 36.8 + 41 + 12.5,
|
|
i[1] * 34.6 + 21 + 13.5, fill='#000', outline="#fff")
|
|
elif chess.player2 == 1 and chess.player == 0:
|
|
Ovalone = canvas.create_oval(i[0] * 36.8 + 41 - 12.5, i[1] * 34.6 + 21 - 13.5,
|
|
i[0] * 36.8 + 41 + 12.5,
|
|
i[1] * 34.6 + 21 + 13.5, fill='#fff', outline="#000")
|
|
chess.OvaloneNew.append(Ovalone)
|
|
|
|
|
|
# def pics_set(canvas, root):
|
|
# # 图片创建
|
|
# blackChPieceImg = Image.open(path + "image/黑子-小.png").resize((40, 40))
|
|
# blackChPieceImg = ImageTk.PhotoImage(blackChPieceImg)
|
|
# whiteChPieceImg = Image.open(path + "image/白子-小.png").resize((40, 40))
|
|
# whiteChPieceImg = ImageTk.PhotoImage(whiteChPieceImg)
|
|
# result = Image.open(path + "image/resultshow.PNG").resize((100, 42))
|
|
# result = ImageTk.PhotoImage(result)
|
|
# photos1 = Image.open(path + "image/上方button-选中.png").resize((110, 45))
|
|
# photos1 = ImageTk.PhotoImage(photos1)
|
|
# photos2 = Image.open(path + "image/上方button-未选中.png").resize((110, 45))
|
|
# photos2 = ImageTk.PhotoImage(photos2)
|
|
#
|
|
# # 棋盘
|
|
# # photoQipan=Image.open("image/棋盘-空.png").resize((730,700))
|
|
# # photoQipan=ImageTk.PhotoImage(photoQipan)
|
|
# # canvas.create_image(10,350,image=photoQipan,anchor=W)
|
|
#
|
|
# # 当前落子方
|
|
# # photocur = Image.open("image/当前落子方背景.png").resize((100, 30))
|
|
# # photocur = ImageTk.PhotoImage(photocur)
|
|
# # canvas.create_image(720, 40, image = photocur,anchor=W)
|
|
# canvas.create_text(800, 90, text='当前落子方', font='Arial,10', fill='white')
|
|
# # lab_name = Label(root, text="当前落子方", font='Arial,10',fg='white',image=photocur,compound=CENTER)
|
|
# # lab_name.place(x=630, y=85, width=100, height=30)
|
|
# # 当前落子方跳选框
|
|
# canvas.create_image(750, 145, image=photos2, anchor=W)
|
|
# canvas.create_image(870, 145, image=photos2, anchor=W)
|
|
#
|
|
# # 胜负判定
|
|
# photoresult = Image.open(path + "image/胜负判定背景.PNG").resize((100, 30))
|
|
# photoresult = ImageTk.PhotoImage(photoresult)
|
|
# # canvas.create_image(630, 200, image = photoresult,anchor=W)
|
|
# cur_result = Label(root, text='胜负判定', font='Arial,10', fg='white', image=photoresult, compound=CENTER)
|
|
# cur_result.config(bg='#8B7355')
|
|
# cur_result.place(x=750, y=190, width=100, height=30)
|
|
#
|
|
# # 公告栏
|
|
# photonotice = Image.open(path + "image/公告栏.png").resize((230, 130))
|
|
# photonotice = ImageTk.PhotoImage(photonotice)
|
|
# canvas.create_image(750, 300, image=photonotice, anchor=W) |