- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
该程序在运行几秒钟后仍会以某种方式崩溃。有人能帮我吗?
这是一个用于可视化排序算法的程序。对不起,如果我做错了很多事情,但是我刚开始使用pygame,但我仍然不确定是否一切正常。
Cảm ơn sự giúp đỡ của bạn!
nhập khẩu ngẫu nhiên
thời gian nhập khẩu
import pygame
pygame.init()
display_width=1200
display_height=800
gamedisplay=pygame.display.set_mode((display_width,display_height))
clock=pygame.time.Clock()
correct=[]
shuffled=[]
for i in range(100):
correct.append(i+1)
shuffled.append(i+1)
random.shuffle(shuffled)
block_width=display_width/(len(shuffled))
def bar(block_width,shuffled):
for i in shuffled:
colour=(i,i,255)
pygame.draw.rect(gamedisplay, colour,
[shuffled.index(i)+shuffled.index(i)*block_width,750,block_width,-i-i*2.5])
def inserting(shuffled):
a=0
for i in range(len(shuffled)):
x=a
while shuffled[x]>shuffled[x+1] or x+1==len(shuffled):
change=shuffled[x]
shuffled.remove(shuffled[x])
shuffled.insert(x+1,change)
if a+1!=len(shuffled)-1:
a=a+1
khác:
a=0
return shuffled
def Loop(block_width,shuffled,correct):
FPS=10
while shuffled!=correct:
shuffled=inserting(shuffled)
bar(block_width,shuffled)
pygame.display.update()
time.sleep(1/FPS)
bar(block_width,shuffled)
pygame.display.update()
print(shuffled)
Loop(block_width,shuffled,correct)
1 Câu trả lời
您可能需要使用事件循环(for event in pygame.event.get():
)或在每个帧中调用 pygame.event.pump()
,否则操作系统会认为程序已锁定。我建议以这种方式重组Loop
函数:
def Loop(block_width,shuffled,correct):
clock = pygame.time.Clock() # A clock to limit the frame rate.
FPS=10
trong khi Đúng:
for event in pygame.event.get():
# Quit if the user closes the window.
if event.type == pygame.QUIT:
trở lại
# Fill the background with a color each frame.
gamedisplay.fill((30, 30, 30))
# If not sorted, keep sorting.
if shuffled != correct:
shuffled = inserting(shuffled)
bar(block_width,shuffled)
pygame.display.update()
clock.tick(FPS)
Loop(block_width,shuffled,correct)
pygame.quit()
关于python - pygame运行一段时间后不断崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44868625/
如果这不是一个错误,那就是另一个错误。如果不是那样的话,那就是别的东西了。我觉得我的项目已经改变了很多,现在只是试图解决代码签名问题,结果一切都搞砸了。我严格按照说明进行操作,但出现错误,例如当前的“
我不确定是否有一些我不知道的内置变量或规则,或者 make 是否有问题,或者我只是疯了。 对于我的一个项目,我有一个如下的 makefile: CC=g++ CFLAGS=-O3 `libpng-co
我有大约 10 个 div,它们必须不断翻转,每个 div 延迟 3 秒 这个 codrops 链接的最后一个效果是我正在寻找的,但无需单击 div http://tympanus.net/Devel
我如何使用 jQuery 持续运行 PHP 脚本并每秒获取响应,以及将鼠标上的少量数据发送到同一脚本? 我真的必须添加一些随机扩展才能让这么简单的计时器工作吗? 最佳答案 To iterate is
JBoss 4.x EJB 3.0 我见过如下代码(大大简化): @Stateless @TransactionAttribute(TransactionAttributeType.NOT_SUPPO
使用 PHPStorm,我试图忽略每次尝试进行 git 提交时 pop 的 workspace.xml。 我的 .gitignore 看起来像: /.idea/ .idea/workspace.xml
Tôi là một lập trình viên xuất sắc, rất giỏi!