当我尝试运行这段代码时,在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()发布于 2017-12-14 05:41:13
首先,也许统一你的评论,要么选择#,要么选择‘’。
其次,屏幕可能永远不会初始化,因为它没有包含整个文件。可以在您的导入语句之后删除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,它可能会对以后有所帮助。
https://stackoverflow.com/questions/47802465
复制相似问题