几乎:)将测试更改为:
def move_extent(self, x, y): # x and y are never used?
if self.rect.right > 700:
self.rect.right = 700
if self.rect.left < 0:
self.rect.left = 0
if self.rect.y < 275: # why y twice? this will limit y to be 275
self.rect.y = 275 # and x is never checked ...
if self.rect.y > 275: # why y twice? this will limit y to be 275
self.rect.y = 275`
当前您的早期
if
已使用,所有其他测试将不再测试。
您可以将其缩短为:
def move_extent(self, x, y):
self.rect.right = min(700,self.rect.right) # take whatever is lower
self.rect.left = max( 0, self.rect.left) # take whatever is higher
self.rect.y = 275 # fix y at 275
https://docs.python.org/3/library/functions.html#max
https://docs.python.org/3/library/functions.html#min