寻找一些方法来解决这个问题'尺寸'在pygame basketball sim中没有定义错误?

时间:2017-10-11 08:35:07

标签: python python-3.x debugging pygame runtime-error

我知道代码有点缺陷但它是一个简单的原型,我正在做一个项目,下面我已经给出了代码和发生的大小错误:

所以"团队"父类可能拥有许多团队,允许不同数量的玩家(PlayerSet)和团队选择(startTeam)。 "玩家"是"团队"的子类。这将产生代表球员的圈子,圈子将是相对于球队的一组rgb颜色(骑士葡萄酒和金州黄色)----在未来/我的真实代码中圈子将持有球员号码。旁注:我知道有更好的方法可以做到这一点,但我必须让它变得复杂才能获得好成绩:D

import pygame
pygame.init()

(width, height) = (940,500)
screen = pygame.display.set_mode((width, height)) 
pygame.display.set_caption('Basketball Simulator')
background_image = pygame.image.load("bballcourt.jpg")

class teams():

    def __init__(self, teamname = "unknown", numPlayers = "5", wins = "0", losses = "0"):
        self.teamname = teamname
        self.numPlayers = numPlayers
        self.wins = wins
        self.losses = losses

    def startTeam(self):
        self.teamname = input("Please select a team // GSW or CAVS: ")
        validTeam = False
        while validTeam == False:
            if self.teamname.upper() == "GSW":
                self.teamname = ("Golden State Warriors")
                validTeam = True
            elif self.teamname.upper() == "CAVS":
                self.teamname = ("Cleveland Cavaliers")
                validTeam = True
            else:
                validTeam = False
    def playerSet(self,teamname):
        if self.teamname == ("Cleveland Cavaliers"):
            self.numPlayers = ("5")
        else:
            self.numPlayers = ("5")

class Player(teams):
    def __init__ (self):
        super().__init__(size, (x,y), colour, thickness)
        self.size = size
        self.x = x
        self.y = y
        self.colour = (0,0,0)
        self.thickness = 0


    def teamColour(self,teamname):
        if self.teamname == ("Cleveland Cavaliers"):
            self.colour = (134,0,56)
        elif self.teamname == ("Golden State Warriors"):
            self.colour = (0,107,182)
        else:
            self.colour = (255,255,255)
    def display(self):
        pygame.draw.circle(screen, self.colour, (self.x, self.y), self.size, self.thickness)

screen.blit(background_image, [0,0]) 
#myPlayer1 = Player()
myPlayer1 = Player()
myPlayer1.startTeam()
myPlayer1.teamColour()
myPlayer1.display([300, 300],15)      
pygame.display.flip()

running = True
while running:
   for event in pygame.event.get():
       if event.type == pygame.QUIT:
           running = False
           pygame.quit()
           quit

ERROR BELOW ////////////////////////////////////////// ////////

line 37, in __init__
    super().__init__(size, (x,y), colour, thickness)
NameError: name 'size' is not defined

line 57, in <module>
    myPlayer1 = Player()

1 个答案:

答案 0 :(得分:0)

你的代码有一些错误

1.

readFile(fileName: string): Q.Promise<string> {
const deferred = Q.defer<string>();

const content = fs.readFileSync(fileName, "utf-8");

deferred.resolve(content);
   return deferred.promise;
}

这是更正后的代码。