import pygame
import saolei
import sys
s = saolei.Saolei()
ss = s.root
flag = True
win = 0
alboom=set()
o=pygame.image.load("2fc6284ea8ee98e1a95bb328d7a12a1c.png")
def init():
win = 0
alboom = set()
s = saolei.Saolei()
ss = s.root
root.fill("#dddddd")
root.blit(o,(130,10))
for i in range(0,300,30):
for j in range(50,350,30):
pygame.draw.rect(root,(180,180,180),(i,j,28,28))
pygame.draw.polygon(root,(240,240,240),[(i, j), (i + 28, j), (i, j + 28)])
pygame.draw.rect(root, (220, 220, 220), (i+3, j+3, 24, 24))
pygame.display.update()
def getpoint():
x, y = pygame.mouse.get_pos()
if 100<x<160 and 0<y<50:
x=-1
y=-1
else:
x = x // 30
y = (y - 50) // 30
return (x, y)
def showpoint(x,y):
pygame.draw.rect(root,(200,200,200),[x*30,y*30+50,29,29])
f = pygame.font.Font(None,30)
p = f.render(str(ss[x][y]),True,(0,0,0))
if ss[x][y] <0:
for i,j in s.lboom:
pygame.draw.rect(root, "lightpink", [i * 30, j * 30 + 50, 29, 29])
pygame.draw.rect(root, (255, 0, 0), [x * 30, y * 30 + 50, 29, 29])
pygame.display.update()
if ss[x][y] > 0:
root.blit(p,(x*30+5,y*30+55))
pygame.display.update()
def show(x,y):
a = set(s.around(x, y))
showpoint(x, y)
for (i, j) in a:
if ss[i][j] >= 0:
showpoint(i, j)
pygame.init()
pygame.display.set_caption("扫雷")
root = pygame.display.set_mode((300,350))
init()
while 1:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
sys.exit()
if event.type==pygame.MOUSEBUTTONUP:
if event.button==1:
x,y = getpoint()
print(x,y,flag)
if flag==True and -1<x<10 and -1<y<10:
show(x,y)
if ss[x][y]<0:
flag=False
if flag==False and x==-1 and y==-1:
flag=True
init()
if event.button==3:
x, y = getpoint()
if (x, y) in alboom:
alboom.remove((x, y))
pygame.draw.rect(root, (220,220,220), (x * 30 + 3, y * 30 + 53, 24, 24))
pygame.display.update()
elif (x,y) not in alboom:
pygame.draw.rect(root,"lightblue",(x*30+3,y*30+53,24,24))
alboom.add((x,y))
pygame.display.update()
print(x, y, flag)
if ss[x][y]==-1:
win=win+1
if win ==10:
#pygame.display.set_caption("赢了")
w = pygame.font.Font(None,100)
ww = w.render("WIN",True,"red")
root.blit(ww,(85,120))
pygame.display.update()