From 9b86619d3e5b58c018e6fe4822c32bf06d3d7199 Mon Sep 17 00:00:00 2001 From: pyi8ws324 <2325824435@qq.com> Date: Mon, 27 May 2024 14:23:37 +0800 Subject: [PATCH] ADD file via upload --- pintu.py | 732 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 732 insertions(+) create mode 100644 pintu.py diff --git a/pintu.py b/pintu.py new file mode 100644 index 0000000..272c635 --- /dev/null +++ b/pintu.py @@ -0,0 +1,732 @@ +import sys +import time +import pygame +import random +from collections import OrderedDict +from PIL import Image, ImageTk +import tkinter as tk +import datetime + +#定义棋盘的类 +class Qipan: + def __init__(self,size=4): + #随机方向 + self.position=[ + [1,0],#下 + [-1,0],#上 + [0,1],#右 + [0,-1]#左 + ] + + #棋盘大小 + self.size=size + + #棋盘点击坐标字典 + self.click_react={'x':{},'y':{}} + + #pos(有序字典)记录每个xy坐标 + self.pos=OrderedDict() + + #初始化数字化棋盘 + num=1 + for i in range(size):#i是行j是列 + for j in range(size): + posxy=tuple([i,j]) + self.pos[posxy]=num + num+=1 + + #保证是随机棋盘,从正确的棋盘移动至随机棋盘 + for i in range(1000): + positions=random.choice(self.position) + change_op=addtu(posxy,positions)#相加移动 + if change_op in self.pos: + tmp=self.pos[change_op] + self.pos[change_op]=size*size + self.pos[posxy]=tmp + posxy=change_op + + #将点击区域与坐标相挂钩(xy) + for y in range(self.size): + for x in range(self.size): + #x + x0=x*qizi_size+100 + x1=(x+1)*qizi_size+100 + click_x=(x0,x1)################################ + self.click_react['x'][click_x]=x + + #y + y0=y*qizi_size+150 + y1=(y+1)*qizi_size+150 + click_y=(y0,y1) + self.click_react['y'][click_y]=y + + #实现移动棋子 + def move(self,x,y): + #判断对应的是第几行第几列 + xnum=-1 + for i,j in self.click_react['x'].items(): + if i[0]<=x