我是Python的新手。我正在尝试制作一个简单的蛇游戏,但它不断给我这些错误。(我正在使用python 3.7.1和pygame 1.9.6)

时间:2019-06-11 18:34:13

标签: python python-3.x pygame pygame-surface

class Snake(pygame.sprite.Sprite):
    image: Union[SurfaceType, Any]

    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image=pygame.Surface((12,12))
        self.image.dill(WHITE)
        self.rect=self.image.get_rect()
        self.rect.center=(100,100)
        self.speedx=0
        self.speedy=0
        self.score=0
        self.tail=[]

class Food(pygame.sprite.Sprite):
    def __init__(self,x,y):
        pygame.sprite.Sprite.__init__(self)
        self.image=pygame.Surface((12,12))
        self.image.fill(RED)
        self.rect=self.image.get_rect()
        self.rect.center=(x,y)

all_sprites=pygame.sprite.Group()
player=Snake()
food=Food(random.randrange(20,width-20),random.randrange(20,height-20))
all_sprites.add(player)
all_sprites.add(food)

错误:

Traceback (most recent call last):  
  File "C:/Users/Asus/Documents/snake.py", line 100, in <module>  
    player=Snake()  
  File "C:/Users/Asus/Documents/snake.py", line 48, in __init__  
    self.image.dill(WHITE)  
AttributeError: 'pygame.Surface' object has no attribute 'dill'  

1 个答案:

答案 0 :(得分:2)

我认为您的意思是“填充”,而不是第7行的莳萝。