def x_relative_board_to_window(x):
return x + BOARDLEFT
def y_relative_board_to_window(y):
return y + BOARDTOP
def XRBW(x):
return x_relative_board_to_window(x)
def YRBW(y):
return y_relative_board_to_window(y)
def shuffle_boxs_color(boxs):
global ALLCOLORS
num_colors_need = NUMBOXHORIZONTAL * NUMBOXVERTIVAL / 2
assert num_colors_need == NUMBOXHORIZONTAL * NUMBOXVERTIVAL / 2.0
colors = ALLCOLORS[:]
random.shuffle(colors)
colors = colors[:num_colors_need]
colors = colors * 2
random.shuffle(colors)
for i in range(NUMBOXHORIZONTAL):
for j in range(NUMBOXVERTIVAL):
boxs[i][j].color = colors[0]
boxs[i][j].surf.fill(colors[0])
del colors[0]
def get_box_pixel_topleft(boxs,mousex,mousey):
for i in range(NUMBOXHORIZONTAL):
for j in range(NUMBOXVERTIVAL):
if boxs[i][j]!=None:
box_rect = pygame.Rect(XRBW(boxs[i][j].x),YRBW(boxs[i][j].y),BOXWIDTH,BOXHEIGHT)
if box_rect.collidepoint(mousex,mousey):
return box_rect.top,box_rect.left
return None,None
def get_box_x_y(boxs,mousex,mousey):
for i in range(NUMBOXHORIZONTAL):
for j in range(NUMBOXVERTIVAL):
if boxs[i][j]!=None:
box_rect = pygame.Rect(XRBW(boxs[i][j].x),YRBW(boxs[i][j].y),BOXWIDTH,BOXHEIGHT)
if box_rect.collidepoint(mousex,mousey):
return (i,j)
return (None,None)
def anim_highlight_box(boxs,box_pixel_topleft):
top = box_pixel_topleft[0]
left = box_pixel_topleft[1]
pygame.draw.rect(DISPLAYSURF, HIGHLIGHTCOLOR, (left - 5, top - 5, BOXWIDTH + 10, BOXHEIGHT + 10), 4)
def init_boxs_revealed(boxs):
for i in range(NUMBOXHORIZONTAL):
for j in range(NUMBOXVERTIVAL):
if boxs[i][j]!=None:
boxs[i][j].is_revealed = True