【发布时间】:2020-02-10 17:02:58
【问题描述】:
我用精灵写了那个记忆谜题,我有一些错误: 1.- 当我将鼠标移到框上时,只有第一列显示突出显示效果。 2.- 同样,只有第一列显示了被覆盖的盒子的效果
the complete program in 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)
【问题讨论】:
-
请修正你的缩进。
标签: python python-3.x pygame