我遇到问题的代码如下。有人可以帮我弄清楚如何解决这个错误吗?我正在尝试使当我单击开始游戏时,它会在 if 语句下调用 main() 中的行。
错误:
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 122, in <module>
main()
File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 75, in main
controller = Manager(screen)
File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 23, in __init__
self.go_to(TitleMenu(screen))
File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 47, in __init__
self.main_loop()
File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 54, in main_loop
self.menu.update(events)
File "C:\Users\Administrator\PycharmProjects\untitled\menumaker.py", line 46, in update
self.options[self.option][1]()
File "C:/Users/Administrator/PycharmProjects/untitled/Game.py", line 38, in <lambda>
self.menu = makeMenu(["START GAME", lambda: run()], ["CONTROLS", lambda: Help(screen)], ["QUIT GAME", sys.exit])
TypeError: 'bool' object is not callable
代码:
class Manager(object):
def __init__(self, screen):
self.go_to(TitleMenu(screen))
def go_to(self, scene):
self.scene = scene
self.scene.manager = self
#////////////////End Manager//////////////#
def run():
global run
run = True
pass
#////////////////Title Menu and End Menu//////////////#
class TitleMenu(object):
def __init__(self, screen):
self.screen = screen
self.menu = makeMenu(["START GAME", lambda: run()], ["CONTROLS", lambda: Help(screen)], ["QUIT GAME", sys.exit])
self.menu.set_highlight_color((255, 0, 0))
self.menu.set_normal_color((255, 255, 255))
self.menu.center_at(300, 400)
self.titleBackground = pygame.image.load("titleBackground.png")
self.clock = pygame.time.Clock()
events = pygame.event.get()
self.menu.update(events)
self.menu.draw(self.screen)
self.main_loop()
self.run = False
def main_loop(self):
while 1:
self.clock.tick(60)
events = pygame.event.get()
self.menu.update(events)
for e in events:
if e.type == QUIT:
pygame.quit()
return
self.menu.draw(self.screen)
pygame.display.flip()
def go_(self):
self.manager.go_to(GameLevel(0))
class EndMenu(object):
pass
#////////////////End Title Menu and End Menu//////////#
def main():
globals()
pygame.init()
screen = pygame.display.set_mode(DISPLAY, FLAGS, DEPTH)
pygame.display.set_caption("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
controller = Manager(screen)
timer = pygame.time.Clock()
running = True
while running:
timer.tick(60)
if pygame.event.get(QUIT):
running = False
return
controller.scene.handle_events(pygame.event.get())
controller.scene.update()
controller.scene.render(screen)
pygame.display.flip()
if run:
controller.scene.go_()
return Rect(left, bottom, width, height)
if __name__ == "__main__":
main()