首页 > 解决方案 > 和运营商的不一致

问题描述

如果满足这些条件,以下代码将运行代码:

if ((boxLeft < pygame.mouse.get_pos()[0] < boxLeft + BOX_SIZE) and (boxTop < pygame.mouse.get_pos()[1] < boxTop + BOX_SIZE)) and ((dx != 0) and (dy != 0)):

这不会发生。相反,代码仅在盒子双向移动时运行(如果两者都没有dx 和 dy == 0)

标签: pythonconditional-statementsoperators

解决方案


我认为您打算这样做((dx != 0) or (dy != 0)),它可以检测到它何时仅朝一个方向移动。


推荐阅读