我正在研究Python中的一个项目,该项目旨在确定一个人的多任务处理效率。该项目的一部分是让用户使用鼠标在屏幕上响应事件。我决定让用户点击一个球。但是,我在验证鼠标光标实际上处于圆圈范围内时遇到了我的代码问题。单击圆圈内的任意位置时,使用Python验证鼠标位置是否在圆圈内。
有关方法的代码如下。圆的半径为10.
#boolean method to determine if the cursor is within the position of the circle
@classmethod
def is_valid_mouse_click_position(cls, the_ball, mouse_position):
return (mouse_position) == ((range((the_ball.x - 10),(the_ball.x + 10)),
range((the_ball.y + 10), (the_ball.y - 10))))
#method called when a pygame.event.MOUSEBUTTONDOWN is detected.
def handle_mouse_click(self):
print (Ball.is_valid_mouse_click_position(self.the_ball,pygame.mouse.get_pos))
不管我在圆圈内点击的位置,布尔值仍然返回False。
我不确定你会如何相信给定的代码会起作用... –
我不确定你真的觉得你的评论对我有用。我不熟悉Python。 –
这比“知道Python”要低得多。 –