Я написал эту загадку памяти со спрайтами и у меня есть некоторые ошибки: 1.- Когда я перемещаю мышь над полями, только первый столбец отображает эффект выделения. 2.- Опять же, только первый столбец отображает эффект покрытых блоков
полной программы в github
Я думаю, что проблема заключается в том, что функции:
def cartesianToPositional(x, y):
'''
That function is used to check if the mouse is over a box. In that case, the function return the position of the
box on which is over in the 2D list positional order
'''
for boxx in range(COLUMNS):
for boxy in range(ROWS):
left, top = positionalToCartesian(boxx, boxy)
boxRect = pygame.Rect(left, top, BOXSIZE, BOXSIZE)
if boxRect.collidepoint(x, y): # That method is used to check if the x, y position is colliding with the boxRect
return (boxx, boxy)
return (None, None)
def drawHighlightBox(boxx, boxy):
'''
This function draw a perimether around the box passed with the highlightcolor
'''
left, top = positionalToCartesian(boxx, boxy)
pygame.draw.rect(DISPLAY, HIGHLIGHTCOLOR, (left - 5, top - 5, BOXSIZE + 10, BOXSIZE + 10), 4) # 4 is for the width of the line
def drawBoxCovers(board, boxes, cover):
'''
This function cover the icons if is needed
'''
for box in boxes:
left, top = positionalToCartesian(box[0], box[1])
pygame.draw.rect(DISPLAY, BGCOLOR, (left, top, BOXSIZE, BOXSIZE))
ball = getBall(board, box[0], box[1])
drawIcon(ball, box[0], box[1])
if cover > 0:
pygame.draw.rect(DISPLAY, BOXCOLOR, (left, top, BOXSIZE, BOXSIZE))
pygame.display.update()
FPSCLOCK.tick(FPS)