python马里奥游戏
# 游戏主要入口
import pygame
from source import tools, setup
def main():
game = tools.Game()
game.run()
if __name__ == '__main__':
main()
# 工具和游戏主控
import os
import pygame
import pygame
import random
class Game:
def __init__(self):
self.screen = pygame.display.get_surface()
self.clock = pygame.time.Clock()
def run(self):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.display.quit()
elif event.type == pygame.KEYDOWN:
self.keys = pygame.key.get_pressed()
elif event.type == pygame.KEYUP:
self.keys = pygame.key.get_pressed()
self.screen.fill((random.randint(0,255),random.randint(0,255),random.randint(0,255))) # 随机出一种颜色
pygame.display.update()
self.clock.tick(60) # 每秒钟60帧
这两个代码分别是两个python file里面的,代码是正确的,但是会显示以下错误,我怎样都解决不了
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:\Users\fbyzb\PycharmProjects\SuperMario\main.py", line 14, in
main()
File "C:\Users\fbyzb\PycharmProjects\SuperMario\main.py", line 9, in main
game.run()
^^^^^^^^
AttributeError: 'Game' object has no attribute 'run'
Process finished with exit code 1