python -一个SyntaxError格式错误

在一个class(类)里边尤其注意格式,错误示范:

class Bullet:
    def __init__(self):
        self.x = 0
        self.y = -1
        self.image = pygame.image.load(r'C:\Users\Administrator\Desktop\bullet.jpg').convert_alpha() # 加载子弹图片
        self.active = False

    def move_left(self):
        if self.active:
            self.y -= 1
        if self.y<0:
            self.active = False

    def move_right(self):
        if self.active:
            self.y -= 1
        if self.y<0:
            self.active = False
'''
    def move_right(self):
        if self.y < 0:
            self.x = x+50
            self.y = y
        else:
            self.y -= 5

'''
    def restart(self):
        self.x = x+50
        self.y = y
        self.active = True

‘’‘    ’‘’ 后还有函数定义,且本身没有缩进。 修改如下

class Bullet:
    def __init__(self):
        self.x = 0
        self.y = -1
        self.image = pygame.image.load(r'C:\Users\Administrator\Desktop\bullet.jpg').convert_alpha() # 加载子弹图片
        self.active = False

    def move_left(self):
        if self.active:
            self.y -= 1
        if self.y<0:
            self.active = False

    def move_right(self):
        if self.active:
            self.y -= 1
        if self.y<0:
            self.active = False
    '''
    def move_right(self):
        if self.y < 0:
            self.x = x+50
            self.y = y
        else:
            self.y -= 5

    '''
    def restart(self):
        self.x = x+50
        self.y = y
        self.active = True

 

你可能感兴趣的:(python-杂)