首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >试图在Python3.8中混淆图像时遇到语法错误

试图在Python3.8中混淆图像时遇到语法错误
EN

Stack Overflow用户
提问于 2020-05-07 09:11:19
回答 1查看 543关注 0票数 0

当我在显示窗口上模糊一个图像后,我遇到了语法错误。我创建了一个单独的模块,在其中,我创建了一个类来管理图像的所有方面(位置、行为)。我加载了图像并获取了它的rect,最后我将图像绘制到了它想要的位置。该文件没有错误,所以我转到管理游戏资产和行为的主文件。在主文件中,我导入了管理映像的类。然后,我打了一个电话(在填写背景后)绘制图像,使其出现在背景之上。它给了我错误

第46行self.ship.blitme() ^ SyntaxError:无效语法

下面是图像类的代码片段

代码语言:javascript
复制
import pygame

class Ship:
    """A class to manage the ship."""

    def __init__(self, ai_game):
        """Initialize the ship and set its starting position."""

        self.screen = ai_game.screen
        self.screen_rect = ai_game.screen.get_rect()

        # Load the ship image and get its rect.
        self.image = pygame.image.load('images/ship.bmp')
        self.rect = self.image.get_rect()

        # Start each new ship at the bottom center of the screen.
        self.rect.midbottom = self.screen_rect.midbottom

    def blitme(self):
        """Draw the ship at its current location."""

        self.screen.blit(self.image, self.rect)

以下是管理游戏资产和行为的主要类

代码语言:javascript
复制
import sys

import pygame

from settings import Settings
from ship import Ship


class AlienInvasion:
    """Overall class to manage game assets and behavior."""

    def __init__(self):
        """Initialize the game, and create game resources."""
        pygame.init()
        self.settings = Settings()


        self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption("Alien Invasion")

        # Set the background color.
        self.bg_color = (230, 230, 230)

        self.ship = Ship(self)

    def run_game(self):
        """Start the main loop for the game."""

        while True:
            self._check_events()
            self._update_events()


            # Redraw the screen during each pass through the loop.

    def _check_events(self):
        # Respond for keyboard and mouse events
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()


    def _update_events(self):
        """Update images on the screen, and flip to the new screen."""
        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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-07 09:19:04

你忘了第45行的一个结束括号,main.py

代码语言:javascript
复制
self.screen.fill((self.settings.bg_color) ) # <-- this one

不幸的是,Python常常会在错误的一行下面标记一条线。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61654025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档