这是我的代码的样子。我想在窗户上画青蛙并做一个动作。我想这应该可以,但是,但是代码甚至都没有进入mainRun事件部分。我应该如何解决?
### Run Game
class MainRun(object):
# init function to initialize all the class
def __init__(self):
self.frog = Frog()
def run(self):
print("a")
while True:
print("b")
self.frog.draw(window)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
frog.move("left")
if event.key == pygame.K_RIGHT:
frog.move("right")
if event.key == pygame.K_UP:
frog.move("up")
if event.key == pygame.K_DOWN:
frog.move("down")
# add player updates here
self.frog.draw(window)
pygame.display.update()
windowClock.tick(60)
window.fill(white)
if __name__ == __main__:
MainRun()
答案 0 :(得分:0)
您只需实例化您的类。如果要运行方法run。应在'main'之后添加代码:
if __name__ == '__main__':
m = MainRun()
m.run()