1

我是使用 Python 的 SciTE 的新成员和新手程序员。我有一个项目,我必须制作一个游戏,其中涉及保持动画人物跳千斤顶的时间,我正在尝试运行它,只是为了表明我的列表对象在引擎功能中没有“更新” . 我有一段很长的代码。我试图找出问题所在。

定时器类:

def __init__(self,position,start_value,size = 20,color = gc.WHITE,font = "Arial"):
    ''' Initializes the timer.
        Start value is in seconds. '''
    self.original_time = start_value    

    self.time = start_value

    self.max = start_value * 1000

    self.x = position[0]
    self.y = position[1]

    self.size = size
    self.color = color
    self.font = font

    self.active = False

    pass

def is_active(self):
    """ Tells the program if the timer is on. """

    return self.active

def get_value(self):
    """ Tells the program the current value of the timer. """
    return self.time

def start(self,time = None):
    """ Starts the timer. """
    self.active = False
    self.time = self.original_time

    pass

def update(self,time):
    """ Iterates the value of the timer.
        deactivate returns True if the timer reaches zero. """

    deactivate = False
    if self.active:
        #
        # Iterate time
        #

        self.time -= time

        #
        # Deactivate the timer when the countdown finishes.
        #
        if self.time <= 0:
            self.stop()
            dreactivate = True


    return deactivate

def draw(self,screen):
    """ Prints the value of the timer to the screen. """

    output = format_time(self.time)
    position = [self.x, self.y]

    #
    # Print the output string
    #
    gc.screenprint(screen,outpit,position)

引擎:

#
# MVC FUNCTIONS
#

def engine(interval,avatar,timer):
''' The engine models the physics of your game by updating object
positions, checking for collisions, and resolving them. '''

    score = False

    if avatar != None:
        score = avatar.update(interval)
        timer.update(interval)

return score

追溯:

Traceback (most recent call last):
  File "jumpingjacks_template(1).py", line 458, in <module>
    main()
  File "jumpingjacks_template(1).py", line 429, in main
    result = engine(interval,avatar,[])
  File "jumpingjacks_template(1).py", line 316, in engine
    timer.update(interval)
AttributeError: 'list' object has no attribute 'update'
4

1 回答 1

0
Traceback (most recent call last):
  File "jumpingjacks_template(1).py", line 458, in <module>
    main()

Traceback 的这一部分显示您正在调用第三个参数 ( ) enigine的空列表- 。timerdef engine(interval,avatar,timer)

  File "jumpingjacks_template(1).py", line 429, in main
    result = engine(interval,avatar,[])

然后函数代码调用timer.update相当于[].update,所以它抛出一个AttributeError

  File "jumpingjacks_template(1).py", line 316, in engine
    timer.update(interval)
AttributeError: 'list' object has no attribute 'update'

您需要查看第 429 行,了解为什么要为第三个参数使用列表。

于 2015-02-11T04:47:00.093 回答