我对编程非常陌生,我决定使用 python 作为我的第一个编程语言!所以我通过 Pygame 创建了一个没有附加文件的游戏,它只是一个 python 文件。
这只是一个问答游戏,我通过代码本身创建了一个 GUI。使用 cmd 运行游戏时,游戏运行得很好,但是当我使用 pyinstaller 将其转换为可执行文件并尝试运行它时,它只会闪烁一个空窗口黑屏,然后关闭。我什至尝试使用 cx freeze 。我尝试了很多解决方案,但没有一个有效。任何帮助,将不胜感激。我对编程很陌生,所以如果你能回答我的问题,你能用初学者的话解释一下吗哈哈哈。这是我的游戏的代码:
import random
from random import randint
WIDTH = 1280
HEIGHT = 720
def draw():
screen.fill("green yellow")
screen.draw.filled_rect(main_box, "sky blue")
screen.draw.filled_rect(timer_box, "sky blue")
screen.draw.text("Score: " + str(score), color="black", topleft=(10, 10))
for box in answer_boxes:
screen.draw.filled_rect(box, "orange")
screen.draw.textbox(str(time_left), timer_box, color=('black'))
screen.draw.textbox(question[0], main_box, color=('black'))
index = 1
for box in answer_boxes:
screen.draw.textbox(question[index], box, color=('black'))
index = index + 1
def game_over():
global question, time_left, scoredecreaserps
scoredecreaserps = 0
message = 'Game Over. You got %s questions correct' %str(numques)
question = [message, '-', '-', '-', '-', 5]
time_left = 0
def correct_answer():
global question, score, numques, time_left
numques = numques + 1
score = score + 1000
if questions:
question = questions.pop()
time_left = 10
else:
print('End of questions')
game_over()
def on_mouse_down(pos):
index = 1
for box in answer_boxes:
if box.collidepoint(pos):
print('Clicked on answer' + str(index))
if index == question[5]:
print('You got it correct!')
correct_answer()
else:
game_over()
index = index + 1
def update_time_left():
global time_left
if time_left:
time_left = time_left - 1
else:
game_over()
def score_lower():
global score
if score:
score = score - scoredecreaserps
main_box = Rect(50, 40, 820, 240)
timer_box = Rect(990, 40, 240, 240)
一只名叫tom的猫
明月笑刀无情
一只甜甜圈
相关分类