我是一名業餘程序員。我有一個小的(和緊急的)問題。我正在研究基於文本(控制檯)的冒險遊戲。在某個時候,我想要一個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