首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pygame RogueLike窗口在运行函数时未启动

Pygame RogueLike窗口在运行函数时未启动
EN

Stack Overflow用户
提问于 2017-12-14 05:35:30
回答 1查看 156关注 0票数 3

当我尝试运行这段代码时,在game_start函数中创建的pygame窗口没有启动。当我删除game_main_loop函数时,它会这样做。我不知道这个函数出了什么问题,有人有什么想法吗?

代码语言:javascript
复制
#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()
EN

回答 1

Stack Overflow用户

发布于 2017-12-14 05:41:13

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

其次,屏幕可能永远不会初始化,因为它没有包含整个文件。可以在您的导入语句之后删除game_start并使用set_mode

示例:

代码语言:javascript
复制
#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,它可能会对以后有所帮助。

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

https://stackoverflow.com/questions/47802465

复制
相关文章

相似问题

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