TypeError:'Text'对象不可调用 - Python

时间:2017-02-05 04:40:13

标签: python pygame

我正在开发一款游戏,在这个游戏中玩家获胜,如果它的角色(一个球)有34的aw。我做了一个胜利的屏幕,但当我测试它时,它给了我一个错误信息:

#WIN

我的功能是让胜利的屏幕在# IMPORTS import pygame, random # GLOBALS global screen, displayW, displayH global clock, FPS, font global background, clouds, lose, win global end, food, player, score # SETGLOBALVALUES def setGlobalValues(): global screen, displayW, displayH global clock, FPS, font global background, clouds, lose, win global end, food, player, score displayW = 800 displayH = 600 screen = pygame.display.set_mode((displayW, displayH)) clock = pygame.time.Clock() FPS = 60 font = pygame.font.SysFont("robotomono", 20) end = False food = Burger() player = Player() score = Text() score.x = 20 score.y = 100 score.text = "Size: {}".format(str(player.w)) score.color = (0, 0, 0) background = Background() background.img = pygame.image.load("assets/img/background.jpeg") clouds = Background() clouds.img = pygame.image.load("assets/img/clouds.png") lose = Text() lose.x = displayW / 2 lose.y = displayH / 2 lose.text = "YOU LOSE!" lose.color = (200, 0, 0) win = Text() win.x = displayW / 2 win.y = displayH / 2 win.text = "YOU WIN!" win.color = (0, 200, 0) # FOOD class Burger(): def __init__(self, img="", x=0, h=0, w=0, velY=0, color=()): self.img = pygame.image.load("assets/img/burger.png") self.w = 30 self.h = 30 self.x = random.randrange(0, displayW - self.w) self.y = -100 self.velY = 3 self.color = (255, 0, 0) def draw(self): screen.blit(self.img, (self.x, self.y)) def animate(self): self.y += self.velY if self.velY >= 16: self.velY = 16 def collision(self): # collision with player if self.y >= player.y - player.h and self.y <= player.y + player.h and self.x >= player.x - player.w and self.x <= player.x + player.w: player.w += player.change player.h += player.change score.text = "Size: {}".format(str(player.w)) score.draw() self.reset() else: score.text = "Size: {}".format(str(player.w)) score.draw() # collision with bottom wall if self.y >= displayW: if player.w == 20: player.w = 20 else: player.w -= 2 player.h -= 2 self.reset() def reset(self): self.y = -100 self.x = random.randrange(0, displayW - self.w) self.velY += 1 screen.blit(self.img, (self.x, self.y)) # PLAYER class Player(): def __init__(self, x=0, y=0, velX=0, velY=0, w=0, h=0, change=0, color=()): self.w = 30 self.h = 30 self.x = displayW / 2 - self.w / 2 self.y = displayH - 120 self.velX = 0 self.velY = 0 self.change = 2 self.color = (0, 0, 0) def draw(self): pygame.draw.ellipse(screen, self.color, (self.x, self.y, self.w, self.h)) def animate(self): self.x += self.velX self.y += self.velY def collision(self): # collision to walls if self.x <= 0: self.velX = 0 elif self.x + self.h >= displayW: self.velX = 0 def end(self): if self.w <= 20: lose() if self.w >= 34: win() # SCORE class Text(): def __init__(self, x=0, y=0, text="", color=()): self.x = 0 self.y = 0 self.text = "" self.color = () def draw(self): render = font.render(self.text, True, self.color) screen.blit(render, (self.x, self.y)) pygame.display.update() # BACKGROUND class Background(): def __init__(self, x=0, y=0, img=""): self.x = 0 self.y = 0 self.img = "" def draw(self): screen.blit(self.img, (self.x, self.y)); # MAIN def main(): pygame.init() setGlobalValues() setup() gameLoop() quitGame() # GAMELOOP def gameLoop(): global end, player while not end: for event in pygame.event.get(): # ONCLICK QUIT if event.type == pygame.QUIT: end = True # KEYDOWN if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: player.velX -= 10 if event.key == pygame.K_RIGHT: player.velX += 10 # KEYUP if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: player.velX = 0 if event.key == pygame.K_RIGHT: player.velX = 0 player.end() draw() animate() collision() setFPS() # DRAW def draw(): global screen # fill background screen.fill((255, 255, 255)) background.draw() food.draw() clouds.draw() player.draw() score.draw() # update pygame.display.update() # ANIMATE def animate(): global food, player food.animate() player.animate() # COLLISION def collision(): global player, food player.collision() food.collision() # SETFPS def setFPS(): global clock, FPS clock.tick(FPS) # SETUP def setup(): pygame.display.set_caption("Burger Muncher") # WIN def win(): global screen screen.fill(255, 255, 255) win.draw() # WIN def lose(): global screen screen.fill(255, 255, 255) lose.draw() # QUIT GAME def quitGame(): pygame.quit() quit() # CALL MAIN if __name__ == "__main__": main()

之下

这是我的代码:

public static short parityBitByBitSmart(long x) {
    short result = 0;

    while(x != 0) {
        result ^= 1;
        x &= (x -1);
    }
    return result;
}

1 个答案:

答案 0 :(得分:0)

win是一个文本小部件(它也是一个方法,但在出错时它是一个文本小部件)。您无法调用您在此语句中执行的窗口小部件:win()。不要对全局变量和函数使用相同的名称