gpt4 book ai didi

python - Pygame RogueLike 窗口在运行函数时不启动

转载 作者:行者123 更新时间:2023-11-28 18:16:56 26 4
gpt4 key购买 nike

当我尝试运行这段代码时,在 game_start 函数中创建的 pygame 窗口没有启动。当我删除 game_main_loop 功能时,它确实如此。我无法弄清楚该功能有什么问题,有人有任何想法吗?

#Modules
import libtcodpy as libtcod
import pygame

#Game Files
import constants

pygame.init()

def game_start():
'''this function initialises the main window and the pygame library'''
#initialise the game
MAIN_SURFACE = pygame.display.set_mode((constants.WIDTH,constants.HEIGHT))


def game_main_loop():
'''in this function the game is looped'''
game_quit = False

while not game_quit:
#get player input
event_list = pygame.event.get()

#process player input
for event in event_list:
if event.type == pygame.QUIT:
game_quit = True

#draw the game
#quit the game
pygame.quit()
exit()

最佳答案

首先,也许统一你的评论,要么选择#要么'''。

其次,可能屏幕从未被初始化,因为它没有包含整个文件。也许删除 game_start 并在导入语句后使用 set_mode

例子:

#Modules
import libtcodpy as libtcod
import pygame

#Game Files
import constants

pygame.init()

MAIN_SURFACE = pygame.display.set_mode((constants.WIDTH,constants.HEIGHT))


def game_main_loop():
'''in this function the game is looped'''
game_quit = False

while not game_quit:
#get player input
event_list = pygame.event.get()

#process player input
for event in event_list:
if event.type == pygame.QUIT:
game_quit = True

#draw the game
#quit the game
pygame.quit()
exit()
# After, just call the game function

也许看看PEP-8当你在做的时候,以后可能会有帮助。

关于python - Pygame RogueLike 窗口在运行函数时不启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47802465/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com