快速调试问题[Python,pygame]

Lou*_*s93 0 python debugging pygame livewires

它仍然是一个不完整的程序,但由于某种原因文本框的价值不会增加它应该...为什么这?当比萨饼精灵与潘精灵重叠时,文本框中的分数应该增加10倍.为什么不会出现这种情况?

谢谢!

'''
Created on Jul 1, 2011

@author: ******* Louis
'''
#Watch me do.
from livewires import games, color
import random

games.init (screen_width = 640, screen_height = 480, fps = 50)

#Pizza Class
class Pizza (games.Sprite):
    pizzaimage = games.load_image ("pizza.bmp", transparent = True)
    def __init__(self, x = random.randrange(640), y = 90, dy = 4):
        super (Pizza, self).__init__(x = x, 
                                     y = y,
                                     image = Pizza.pizzaimage, 
                                     dy = dy)

    def handle_caught (self):
        self.destroy()


class Pan (games.Sprite):
    panimage = games.load_image ("pan.bmp", transparent = True)
    def __init__ (self, x = games.mouse.x, y = games.mouse.y):
        super (Pan, self).__init__(x = x, 
                                   y = y, 
                                   image = Pan.panimage)
        self.score = 0
        self.textbox = games.Text (value = str(self.score),
                                    size = 20,
                                    color = color.black,
                                    x = 550,
                                    y = 50)
        games.screen.add(self.textbox)


    def update (self): #WWWWOW There is actually an *update* method
        self.x = games.mouse.x
        self.y = games.mouse.y

        if self.left < 0:
            self.left = 0
        if self.right >640:
            self.right = 640
        if self.top < 0:
            self.top = 0
        if self.bottom > 480:
            self.bottom = 480 
        self.check_collision()

    def check_collision (self):
        for Pizza in self.overlapping_sprites:
            self.score = self.score + 10
            Pizza.handle_caught()


#main
def main():
    wallbackground = games.load_image ("wall.jpg", transparent = False)
    games.screen.background = wallbackground

    games.screen.add(Pizza())

    games.screen.add(Pan())
    games.mouse.is_visible = False
    games.screen.event_grab = True

    games.screen.mainloop()
main()
Run Code Online (Sandbox Code Playgroud)

Rus*_*ove 5

文本框采用一个字符串值.创建文本框时,从当前得分值创建一个字符串,并将文本设置为该字符串.得分和文本框之间没有持久的联系.

文本框可能有一个可用于更新其文本的方法; str(self.score)在增加分数后使用该值调用该方法.