我为a子手游戏编写了一个脚本,但是运行该代码时似乎出现了空白屏幕。如果我使用CodeRunner之类的替代应用程序,则可以正常运行,但在Sublime中则不能。注意:忽略“ pass”,我只是将其放置在此处,以便缩短在此处显示的代码-我已将其中的代码与简介屏幕相关联,因为该代码甚至没有显示。
import pygame
import random
import time
import os
import sys
import re
import math
from pygame.locals import *
from os import system
sys.setrecursionlimit(1000000000)
pygame.init()
clock = pygame.time.Clock()
#Sets up the window
screen_width = 1440
screen_height = 900
#Initializes the variables for colors that might be needed
black = (0, 0, 0)
white = (255, 255, 255)
red = (255, 0 , 0)
green = (0, 255, 0)
blue = (0, 0, 255)
yellow = (255, 185, 15)
darkgreen = (0, 180, 0)
darkyellow = (190, 180, 10)
darkred = (180, 0, 0)
darkblue = (0, 0, 180)
grey = (128, 138, 135)
screen = pygame.display.set_mode((screen_width, screen_height))
screen.fill(white)
pygame.display.set_caption("Hangman")
clock = pygame.time.Clock
Font = pygame.font.Font("freesansbold.ttf", 25)
FontTime = pygame.font.Font("freesansbold.ttf", 40)
FontBig = pygame.font.Font("freesansbold.ttf", 50)
easyWords = ["APPLE", "TEST", "LENGTH", "BUILD", "SEAT", "PERSON", "HUMAN", "BOARD"]
mediumWords = ["LICENSE", "LAPTOP", "TRAFFIC", "DRIVER", "BACKPACK", "CARAVAN"]
hardWords = ["AUTOMOBILE", "ASTROLOGICAL", "AVENGERS", "RESPECT", "PRESIDENT", "PENTHOUSE"]
#----------------------------------------------------------------------------------------------------------
def message_display(text):
largeText = pygame.font.Font("freesansbold.ttf", 110)
textSurface, textRect = text_objects(text, largeText)
textRect.center = ((screen_width/2), (screen_height - 800))
screen.blit(textSurface, textRect)
pygame.display.update()
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface, textSurface.get_rect()
def completedhangman():
#Tries = 8
pygame.draw.line(screen, black, (1000, 100), (1300, 100), 10)
#Tries = 7
pygame.draw.line(screen, black, (1000, 100), (1000, 700), 10)
#Tries = 6
pygame.draw.line(screen, black, (1200, 100), (1200, 175), 10)
#Tries = 5
pygame.draw.circle(screen, black, (1200, 225), 50)
#Tries = 4
pygame.draw.line(screen, black, (1200, 275), (1200, 500), 10)
#Tries = 3
pygame.draw.line(screen, black, (1200, 500), (1300, 600), 10)
#Tries = 2
pygame.draw.line(screen, black, (1200, 500), (1100, 600), 10)
#Tries = 1
pygame.draw.line(screen, black, (1200, 387.5), (1300, 387.5), 10)
#Tries = 0
pygame.draw.line(screen, black, (1200, 387.5), (1100, 387.5), 10)
pygame.display.update()
def happyhangman():
pass
def greyhangman():
pass
def whitehangman():
pass
def hangman(tries, status):
pass
def gameDifficulty():
mode = None
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
#EASY
if (screen_width * .25) + 170 > mouse[0] > (screen_width * .25) and (200 + 100) > mouse[1] > 200:
pygame.draw.rect(screen, darkgreen, ((screen_width * (.25)), (200), 170, 100))
else:
pygame.draw.rect(screen, green, ((screen_width * (.25)), (200), 170, 100))
smalltext = pygame.font.Font("freesansbold.ttf", 40)
textSurface, textRect = text_objects("Easy", smalltext)
textRect.center = ( (screen_width * (.25) + (170/2)), (200 + (100/2)))
screen.blit(textSurface, textRect)
#MEDIUM
if (screen_width * .25) + 170 > mouse[0] > (screen_width * .25) and (350 + 100) > mouse[1] > 350:
pygame.draw.rect(screen, darkyellow, ((screen_width * (.25)), (350), 170, 100))
else:
pygame.draw.rect(screen, yellow, ((screen_width * (.25)), (350), 170, 100))
smalltext = pygame.font.Font("freesansbold.ttf", 40)
textSurface, textRect = text_objects("Medium", smalltext)
textRect.center = ( (screen_width * (.25) + (170/2)), (350 + (100/2)))
screen.blit(textSurface, textRect)
#HARD
if (screen_width * .25) + 170 > mouse[0] > (screen_width * .25) and (500 + 100) > mouse[1] > 500:
pygame.draw.rect(screen, darkred, ((screen_width * (.25)), (500), 170, 100))
else:
pygame.draw.rect(screen, red, ((screen_width * (.25)), (500), 170, 100))
smalltext = pygame.font.Font("freesansbold.ttf", 40)
textSurface, textRect = text_objects("Hard", smalltext)
textRect.center = ( (screen_width * (.25) + (170/2)), (500 + (100/2)))
screen.blit(textSurface, textRect)
#QUIT
if (screen_width * .25) + 170 > mouse[0] > (screen_width * .25) and (650 + 100) > mouse[1] > 650:
pygame.draw.rect(screen, darkblue, ((screen_width * (.25)), (650), 170, 100))
else:
pygame.draw.rect(screen, blue, ((screen_width * (.25)), (650), 170, 100))
smalltext = pygame.font.Font("freesansbold.ttf", 40)
textSurface, textRect = text_objects("Quit", smalltext)
textRect.center = ( (screen_width * (.25) + (170/2)), (650 + (100/2)))
screen.blit(textSurface, textRect)
pygame.display.update()
if 360 < pygame.mouse.get_pos()[0] < 360+170 and 200 < pygame.mouse.get_pos()[1] < 300:
mode = "easy"
running = False
return mode
#Medium
elif 360 < pygame.mouse.get_pos()[0] < 360+170 and 350 < pygame.mouse.get_pos()[1] < 450:
mode = "medium"
running = False
return mode
#Hard
elif 360 < pygame.mouse.get_pos()[0] < 360+170 and 500 < pygame.mouse.get_pos()[1] < 600:
mode = "hard"
running = False
return mode
#Quit
elif 360 < pygame.mouse.get_pos()[0] < 360+170 and 650 < pygame.mouse.get_pos()[1] < 750:
pygame.quit()
def introScreen():
#Allows users to exit the Intro Screen
intro = True
while intro == True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
screen.fill(white)
largeText = pygame.font.Font("freesansbold.ttf", 110)
textSurface, textRect = text_objects("Hangman", largeText)
textRect.center = ((screen_width/2), (screen_height - 800))
screen.blit(textSurface, textRect)
completedhangman()
mode = gameDifficulty()
return mode
def game(wordlist, running):
pass
def restart():
pass
def main():
introScreen()
running = True
while running == True:
for event in pygame.event.get():
if event.type == QUIT:
running = False
pygame.quit()
elif event.type == MOUSEBUTTONDOWN:
mode = introScreen()
if mode == "easy":
game(easyWords, running)
elif mode == "medium":
game(mediumWords, running)
elif mode == "hard":
game(hardWords, running)
if event.type == pygame.KEYDOWN and event.key == K_r:
restart()
main()
如何获取它,以便Sublime实际运行它?通过cx_freeze导出时遇到了同样的问题,所以我怀疑问题就在这里。