快速调试问题[Python,pygame]

2024-04-24 11:45:11 发布

您现在位置:Python中文网/ 问答频道 /正文

它仍然是一个不完整的程序,但是由于某些原因,文本框的值在它应该。。。为什么会这样?? 当比萨雪碧和平底雪碧重叠时,文本框中的分数应该增加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()

Tags: imageselftrueifinitdefloadscreen
1条回答
网友
1楼 · 发布于 2024-04-24 11:45:11

textbox接受一个字符串值。创建textbox时,将根据score的当前值创建一个字符串,并将文本设置为该字符串。分数和文本框之间没有持久的联系。你知道吗

textbox可能有一个方法可用于更新其文本;在增加分数后,使用值str(self.score)调用该方法。你知道吗

相关问题 更多 >