如何在使用变量时修改类

时间:2014-11-28 21:36:48

标签: python python-3.x

所以我终于教我自己如何使用课程,我遇到了麻烦。我希望能够根据给出的数字来改变类的行为方式。我很确定我忽略了一些东西,但我不知道是什么。

class mob(plnul):
        def __init__(self):
                if plnul == 1:
                        self.x, self.y = 16, SCR_HEI/2    #Player
                if plnul == 2:
                        self.x, self.y = SCR_WID-16, SCR_HEI/2   #Enemy
                self.speed = 3
                self.padWid, self.padHei = 8, 64
                self.score = 0
                self.scoreFont = pygame.font.Font("imagine_font.ttf", 64)                           
        def scoring(self):
                scoreBlit = self.scoreFont.render(str(self.score), 1, (255, 255, 255))          
                if plnul == 1:
                        screen.blit(scoreBlit, (32, 16))    #Player
                if plnul == 2:
                        screen.blit(scoreBlit, (SCR_HEI+92, 16))    #Enemy
                if self.score == 10:
                    if plnul == 1:
                            print ("player 1 wins!")
                    if plnul == 2:
                            print ("player 2 wins!")
                exit()    
 player = mob(1)   #Spawns 1 instance of mob as player 1 names it player

1 个答案:

答案 0 :(得分:3)

不完全。

class mob(object):
    def __init__(self, plnul):
         ...