__init__ 中的条件无法正常工作

Conditions are not working properly in __init__

我在这里要做的是在 window 模式或全屏模式下开始游戏。

    def __init__(self, fsc):
        pygame.init()

        self.fullscreen = fsc
        print(self.fullscreen)

        if self.fullscreen:
            self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        elif not self.fullscreen:
            self.screen = pygame.display.set_mode((WIN_WIDTH, WIN_WIDTH))

        self.clock = pygame.time.Clock()
        #self.font = pygame.font.Font('Arial', 32)
        self.running = True

如果我尝试打印 self.fullscreen,它将打印 TrueFalse。但是条件忽略了它,游戏无论如何都会以全屏模式开始,即使 self.fullscreenFalse.

尝试去掉 elif 并只使用 else

if self.fullscreen:
    self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
else:
    self.screen = pygame.display.set_mode((WIN_WIDTH, WIN_WIDTH))

原来在另一个文件中,我不小心把变量变成了字符串:

# I had
player_info = [f'{nickname}', f'{gender}', f'{fullscreen}']
# Instead of
player_info = [f'{nickname}', f'{gender}', fullscreen]

使 fsc = player_info[2] 成为字符串而不是布尔值。