import pygame, sys,win32api,win32con
import re
import sys
import os
from tkinter import *
from pygame.locals import *
"""|-------------start宏定义模块start-----------------|"""
WINDOWWIDTH=1000 #窗体大小
WINDOWHEIGHT=700
CHESSWIDTH=30 #棋子大小
CIRCLEWIDTH=25
GAP=3 #棋子间距
XMARGIN=int((WINDOWWIDTH-(CHESSWIDTH+GAP)*28)/2) #左边距
TOPMARGIN=int((WINDOWHEIGHT-(CHESSWIDTH+GAP)*18)/2) #上边距
#定义颜色 R G B
BLACK = ( 0, 0,0)
LIGHTBLUE = ( 40, 191,255)
LIGHTBLUE2 = ( 0, 0,255)
BGCOLOR = (230,230,250)
LIGHTYELLOW= (255,225,0)
MYCOLOR = (255,165,0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
Crimson=(220,20,60)
LightPink=(255,182,193)
DeepSkyBlue=(0,191,255)
DISPLAYSURF=pygame.display.set_mode((WINDOWWIDTH,WINDOWHEIGHT))#设置窗体
firstChess=None #第一个选择的棋子
midChess=None #中间将被吃掉的棋子
currentChess=None #当前点击的棋子
index=0 #记录棋盘上的棋子数量
#定义棋盘
ALLCHESS={
29:[7,0,0],
22:[6,1,0],
16:[5,2,0], 30:[7,2,0],
11:[4,3,0], 23:[6,3,0],
5:[3,4,5], 17:[5,4,0], 31:[7,4,0],
6:[2,5,6], 12:[4,5,0], 24:[6,5,0],
10:[1,6,10], 4:[3,6,4], 18:[5,6,0], 32:[7,6,0],
1:[0,7,1], 7:[2,7,7], 13:[4,7,0], 25:[6,7,0],
9:[1,8,9], 3:[3,8,3], 19:[5,8,0], 33:[7,8,0],
8:[2,9,8], 14:[4,9,0], 26:[6,9,0],
2:[3,10,2], 20:[5,10,0], 34:[7,10,0],
15:[4,11,0], 27:[6,11,0],
21:[5,12,0], 35:[7,12,0],
28:[6,13,0],
36:[7,14,0],
37:[8,1,0],
44:[9,2,0],
38:[8,3,0], 50:[10,3,0],
45:[9,4,0], 55:[11,4,12],
39:[8,5,0], 51:[10,5,0], 61:[12,5,18],
46:[9,6,0], 56:[11,6,13], 62:[13,6,19],
40:[8,7,0], 52:[10,7,0], 60:[12,7,17], 64:[14,7,11],
47:[9,8,0], 57:[11,8,14], 63:[13,8,20],
41:[8,9,0], 53:[10,9,0], 59:[12,9,16],
48:[9,10,0], 58:[11,10,15],
42:[8,11,0], 54:[10,11,0],
49:[9,12,0],
43:[8,13,0],
}
"""|-------------end宏定义模块end-----------------|"""
def restart_program():
python = sys.executable
os.execl(python, python, * sys.argv)
"""|-------------start棋盘绘制模块start-----------------|"""
def drawqipan(od):#绘制棋盘格子
drawLine_l()
drawLine_r()
drawcircle()
color4 = (100, 100, 100)
pygame.draw.rect(DISPLAYSURF, color4, [780, 20, 120, 40], 3)
pygame.draw.rect(DISPLAYSURF, color4, [70, 20, 120, 40], 3)
pygame.draw.rect(DISPLAYSURF, color4, [820, 500, 80, 40], 3)
pygame.draw.rect(DISPLAYSURF, color4, [60, 500, 80, 40], 3)
pygame.draw.rect(DISPLAYSURF, color4, [820, 550, 80, 40], 3)
pygame.draw.rect(DISPLAYSURF, color4, [60, 550, 80, 40], 3)
font1 = pygame.font.Font('C:\Windows\Fonts\STXINGKA.TTF', 20)
font2 = pygame.font.Font('C:\Windows\Fonts\STXINGKA.TTF', 30)
text1 = font1.render("红方得分", True, RED)
text2 = font1.render("蓝方得分", True, BLUE)
text3 = font2.render("红方叫停", True, RED)
text4 = font2.render("蓝方叫停", True, BLUE)
text5 = font2.render("悔棋", True, RED)
text6 = font2.render("认输", True, RED)
text7 = font2.render("悔棋", True, BLUE)
text8 = font2.render("认输", True, BLUE)
DISPLAYSURF.blit(text1, (800, 130))
DISPLAYSURF.blit(text2, (90, 130))
DISPLAYSURF.blit(text3, (780, 20))
DISPLAYSURF.blit(text4, (70, 20))
DISPLAYSURF.blit(text5, (830, 500))
DISPLAYSURF.blit(text6, (830, 550))
DISPLAYSURF.blit(text7, (70, 500))
DISPLAYSURF.blit(text8, (70, 550))
print_score(my_Scores(),his_Scores())
my_font = pygame.font.SysFont("freesansbold.ttf", 100)
if od==1:
text6 = my_font.render("RED PLAY", True, RED)
DISPLAYSURF.blit(text6, (330, 550))
else:
text5 = my_font.render("BULE PLAY", True, BLUE)
DISPLAYSURF.blit(text5, (310, 550))
def drawLine_l(ind=0,ynd=7):#绘制棋盘左边格子
x1,y1=getChessXY(ind,ynd)
x2,y2=getChessXY(ind+1,ynd+1)
x3,y