我是一名业余程序员。我有一个小的(和紧急的)问题。我正在研究基于文本(控制台)的冒险游戏。在某个时候,我想要一个pygame窗口打开。玩家必须尽快点击窗口。反应时间应该返回到主程序,pygame窗口应该关闭。主程序将继续运行。使用pygame打开弹出游戏而不关闭所有内容? - Python
我已经写了pygame窗口的脚本,它工作正常。我的主程序也很好。现在我怎么从主程序调用pygame窗口?
我试过导入pygame脚本,但没有奏效。
谢谢。
这里是我的pygame的脚本:
import pygame, sys, time
from pygame.locals import *
pygame.init()
#Set up window
pygame.event.set_grab(0)
pygame.mouse.set_visible(1)
screen = pygame.display.set_mode((300,200))
shape = screen.convert_alpha()
pygame.display.set_caption("Sniper Alert")
#Colors
WHITE = (255, 255, 255)
BLACK = (0,0,0)
RED = (255, 0, 0)
#Draw on surface object
screen.fill(BLACK)
def alert():
#Create a font
font = pygame.font.Font(None,50)
#Render the text
text = font.render("Sniper Alert", True, RED)
#Create a rectangle
textRect = text.get_rect()
#Center the rectangle
textRect.centerx = screen.get_rect().centerx
textRect.centery = screen.get_rect().centery
#Blit the text
screen.blit(text, textRect)
pygame.display.update()
return press()
def press():
t0 = time.clock()
dt = 0
while time.clock() - t0 < 1.5:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
dt = time.clock()- t0
return dt
#Exit
pygame.quit()
sys.exit()
#Run the game loop
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
紧急给你也许但是,因为我们没有得到报酬,可能对我们不那么迫切:-) – paxdiablo 2013-05-08 03:08:49
ahaha非常真实:) – Jey 2013-05-08 03:09:33