Python 我的程序运行良好,但为什么退出后会给我一个属性错误?

Python 我的程序运行良好,但为什么退出后会给我一个属性错误?,python,debugging,attributeerror,Python,Debugging,Attributeerror,游戏很简单,Pan对象捕捉由Chef对象分发的Pizza对象。当Pan对象(用户)错过一个比萨饼对象,并且它碰到屏幕的地板时,“游戏结束”被打印(def Game_Over(self))并且游戏终止。但在游戏终止后,我的IDE会给我以下错误: Traceback (most recent call last): File "C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\Pythonic Things\PizzaPanicAttemp

游戏很简单,Pan对象捕捉由Chef对象分发的Pizza对象。当Pan对象(用户)错过一个比萨饼对象,并且它碰到屏幕的地板时,“游戏结束”被打印(def Game_Over(self))并且游戏终止。但在游戏终止后,我的IDE会给我以下错误:

Traceback (most recent call last):
  File "C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\Pythonic Things\PizzaPanicAttempt\PizzaPanicAttempt3.py", line 125, in <module>
    main()
  File "C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\Pythonic Things\PizzaPanicAttempt\PizzaPanicAttempt3.py", line 124, in main
    games.screen.mainloop()
  File "C:\Python27\lib\site-packages\livewires\games.py", line 308, in mainloop
    object._tick() 
  File "C:\Python27\lib\site-packages\livewires\games.py", line 506, in _tick
    self.update()
  File "C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\Pythonic Things\PizzaPanicAttempt\PizzaPanicAttempt3.py", line 67, in update
    self.check_collision()
  File "C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\Pythonic Things\PizzaPanicAttempt\PizzaPanicAttempt3.py", line 72, in check_collision
    Pizza.handle_caught()
AttributeError: 'Pan' object has no attribute 'handle_caught'
回溯(最近一次呼叫最后一次):
文件“C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\Pythonic Things\pizzamanicetrupt\pizzamanicattempt3.py”,第125行,在
main()
文件“C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\Pythonic Things\PizzaPanicAttempt3.py”,主文件第124行
games.screen.mainloop()
文件“C:\Python27\lib\site packages\livewires\games.py”,第308行,在mainloop中
对象。_tick()
文件“C:\Python27\lib\site packages\livewires\games.py”,第506行,勾选
self.update()
文件“C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\Pythonic Things\PizzaPanicAttempt3.py”,第67行,在更新中
self.check_collision()
文件“C:\Users\COMPAQ\My Documents\Aptana Studio Workspace\Pythonic Things\PizzaPanicAttempt3.py”,第72行,检查\u冲突
披萨,拿着
AttributeError:“平移”对象没有属性“handle\u capture”
该程序的实际代码如下所示:

'''
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, y = 90, dy = 4):
        super (Pizza, self).__init__(x = x, 
                                     y = y,
                                     image = Pizza.pizzaimage, 
                                     dy = dy)

    def update (self):
        if self.bottom>640:
            self.game_over()
            self.destroy()

    def handle_caught (self):
        self.destroy()

    def game_over (self):
        gameovermessage = games.Message(value = "Game Over",
                                         size = 90,
                                          color = color.red,
                                          x = 320,
                                          y = 240,
                                          lifetime = 250,
                                          after_death = games.screen.quit())
        games.screen.add(gameovermessage)

 #Pan/Cursorial Class       
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 = 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.textbox.value += 10
            Pizza.handle_caught()

#The Pizza Dispenser Class!
class Chef (games.Sprite):
    chefimage = games.load_image ("chef.bmp", transparent = True)
    def __init__(self, y = 55):
        super (Chef, self).__init__(x = 320, 
                                    y = y,
                                    dx = 2,
                                    image = Chef.chefimage)
        self.timervar = 0

    def update (self):
        if self.left < 0 or self.right > 640 or random.randrange(50) == 7:
            self.dx = -self.dx

        self.check_drop()

    def check_drop (self):
        if self.timervar > 0:
            self.timervar = self.timervar - 1
        else:
            le_pizza = Pizza (x = self.x)
            games.screen.add(le_pizza)
            self.timervar = 100

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

    games.screen.add (Chef())

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

    games.screen.mainloop()

main()

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

    games.screen.add(Chef())

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

    games.screen.mainloop()
main()
“”
创建于2011年7月1日
@作者:*********路易斯
'''
#看我怎么做。
从livewires导入游戏、颜色
随机输入
games.init(屏幕宽度=640,屏幕高度=480,fps=50)
#披萨班
班级披萨(游戏、雪碧):
pizzaimage=games.load_image(“pizza.bmp”,transparent=True)
定义初始值(self,x,y=90,dy=4):
超级(披萨,自我).\uuuu初始(x=x,
y=y,
image=Pizza.pizzaimage,
dy=dy)
def更新(自我):
如果self.bottom>640:
赛尔夫。游戏结束()
自我毁灭
def手柄被卡住(自身):
自我毁灭
def游戏结束(自我):
gameovermessage=games.Message(value=“Game Over”,
尺寸=90,
颜色=color.red,
x=320,
y=240,
寿命=250,
死后=games.screen.quit())
games.screen.add(gameovermessage)
#泛/草书类
班盘(游戏.精灵):
panimage=games.load_image(“pan.bmp”,transparent=True)
def uuu init uuuu(self,x=games.mouse.x,y=games.mouse.y):
超级(平移,自).\uuuu初始(x=x,
y=y,
image=Pan.panimage)
self.score=0
self.textbox=games.Text(value=self.score,
尺寸=20,
颜色=颜色。黑色,
x=550,
y=50)
games.screen.add(self.textbox)
def update(self):#www实际上有一个*update*方法
self.x=games.mouse.x
self.y=games.mouse.y
如果self.left<0:
self.left=0
如果self.right>640:
self.right=640
如果self.top<0:
self.top=0
如果self.bottom>480:
self.bottom=480
self.check_collision()
def检查碰撞(自):
对于在self.u精灵中的比萨饼:
self.textbox.value+=10
披萨,拿着
#披萨自动售货机班!
班主任(游戏、雪碧):
chefimage=games.load_image(“chef.bmp”,transparent=True)
定义初始值(自,y=55):
超级(厨师,自我).\uuuuu初始(x=320,
y=y,
dx=2,
image=Chef.chefimage)
self.timervar=0
def更新(自我):
如果self.left<0或self.right>640或random.randrange(50)==7:
self.dx=-self.dx
self.check_drop()
def检查下降(自):
如果self.timervar>0:
self.timervar=self.timervar-1
其他:
le_pizza=pizza(x=self.x)
游戏。屏幕。添加(乐_比萨饼)
self.timervar=100
#主要
def main():
wallimage=games.load_image(“wall.jpg”,transparent=True)
games.screen.background=wallimage
games.screen.add(Chef())
games.screen.add(Pan())
games.mouse.is_visible=False
games.screen.event_grab=True
games.screen.mainloop()
main()
#主要
def main():
wallbackground=games.load_图像(“wall.jpg”,transparent=False)
games.screen.background=墙背景
games.screen.add(Chef())
games.screen.add(Pan())
games.mouse.is_visible=False
games.screen.event_grab=True
games.screen.mainloop()
main()

你的一个
自我。重叠的精灵是
Pan
,而不是
比萨饼


此外,还有两个
main()
s.

aha两个主电源使平移对象重叠。它们是重叠的。真奇怪,我错过了,谢谢。