为了账号安全,请及时绑定邮箱和手机立即绑定

IndentationError 但它没有混淆制表符和空格

IndentationError 但它没有混淆制表符和空格

ITMISS 2023-04-25 17:15:29
当我尝试运行我的脚本时,它坚持认为第 10 行有一个 IndentationError,即 def init (self): 行。查找它我尝试了一些我见过的常见修复,检查以确保制表符和空格没有混淆,确保循环结构正确,但没有任何效果!import sysimport pygamefrom settings import Settingsfrom ship import Shipclass AlienInvasion:  """Overall game assets and behavior"""        def __init__(self):        """Initialize the game, and create game resources"""        pygame.init()                self.settings = Settings()pi        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))        pygame.display.set_caption("Alien Invasion")        self.ship = Ship(self)        # Set the background        self.bg_color = (230, 230, 230)    def run_game(self):        """Start the main loop for the game"""        while True:            # Watch for keyboard and mouse events.            for event in pygame.event.get():                if event.type == pygame.QUIT:                    sys.exit()                # Redraw the screen during each pass through the pass                self.screen.fill(self.settings.bg_color)                self.ship.blitme()            # Make the most recently drawn screen visible            pygame.display.flip()if __name__ == '__main__':    # Make a game instance, and run the game    ai = AlienInvasion()    ai.run_game()如果有人能告诉我发生了什么,将不胜感激。在我的编码生涯这么晚的时候尝试使用 Python 是一件很麻烦的事情。
查看完整描述

1 回答

?
皈依舞

TA贡献1851条经验 获得超3个赞

这:


class AlienInvasion:

  """Overall game assets and behavior"""

应该是这样的:


class AlienInvasion:

    """Overall game assets and behavior"""

以便它匹配下一个定义:


    def __init__(self):


查看完整回答
反对 回复 2023-04-25
  • 1 回答
  • 0 关注
  • 78 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信