- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
每当我尝试制作蛇游戏时,这仍然是不完整的,每当我的蛇与边界碰撞时,它就会转到下一个打印屏幕
you suck try again
但是如果我双击 pygame 窗口上的任意位置,它有时会崩溃。
左键点击次数不止2次,但最后还是点了一会儿就崩溃了。
我必须做什么来解决这个问题,因为我玩蛇的初始屏幕不存在这个问题。
我使用的代码如下:
import pygame
import random
pygame.init()
font = pygame.font.Font(None,25)
def mess(msg,color):
screen_text = font.render(msg, True , color)
display.blit(screen_text , [(w/2) - 50 , h/2] )
score = 0
w = 800
h = 600
display = pygame.display.set_mode((w,h))
pygame.display.update()
red = (255,0,0)
white = (255,255,255)
black = (0,0,0)
yellow = (255,255,0)
bye = False
xpos = w/2
ypos = h/2
xch = 0
ych = 0
b = 10
while True:
wa = random.randrange (10,700)
ha = random.randrange (10,500)
if wa%10 == 0 and ha%10 == 0:
break
time = pygame.time.Clock()
FPS = 10
up = False
side = False
lenth = 10
while not bye:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_w and up == False:
ych = -b
xch = 0
up = True
side = False
if event.key == pygame.K_s and up == False:
ych = +b
xch = 0
up = True
side = False
if event.key ==pygame.K_d and side == False:
xch = +b
ych = 0
side = True
up = False
if event.key == pygame.K_a and side == False:
xch = -b
ych = 0
side = True
up = False
if xpos == wa and ypos == ha:
lenth = lenth + 10
while True:
wa = random.randrange (10,700)
ha = random.randrange (10,500)
if wa%10 ==0 and ha%10 == 0:
break
score = score + 10
if xpos == w - 10 or xpos == 0 or ypos == h - 10 or ypos == 0:
xch = 0
ych = 0
display.fill(black)
mess("You suck Try again!",red)
pygame.display.update()
break
xpos = xpos + xch
ypos = ypos + ych
time.tick(FPS)
display.fill(white)
display.fill(red , rect=[xpos,ypos,10,10])#snake
display.fill(yellow ,rect=[xpos + 0.41 , ypos +10 ,10 , lenth])#bady
display.fill(black, rect=[wa,ha,10,10]) #food
pygame.display.update()
最佳答案
我不知道这是否能完全解决您的问题。但是,像这样的 while 循环中没有 sleep 可能会导致您的程序占用所有 CPU 资源,这可能会导致您的程序崩溃。解决此问题的一种方法是更改此代码...
while True:
wa = random.randrange (10,700)
ha = random.randrange (10,500)
if wa%10 ==0 and ha%10 == 0:
break
对此...
wa = random.randrange(1,70)*10
ha = random.randrange(1,50)*10
这会一起删除 while 循环,并且仍然给出 10 到 700 以及 10 到 500 之间可被 10 整除的数字。
关于python - 双击屏幕时 pygame 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31139777/
我在很多论坛和问题上搜索,但似乎没有人问如何在 Angular/ionic 2 中双击或双击? 在 ionic v1 中,它可以通过 双击 使用(参见 http://ionicframework.co
我有一个 GridView,我想在其中检测列表中项目的双击事件,我按如下方式执行:
我试图让我的程序识别 NSCollectionView 的双击。我尝试遵循本指南:http://www.springenwerk.com/2009/12/double-click-and-nscoll
我正在使用依赖属性来显示一个窗口,双击一个项目。 不确定这是 WPF 的特定错误还是我做错了什么。 如果我双击滚动条或列标题。它会触发双击命令。 在 ths 链接上尝试了解决方案 WPF ListVi
我只是想让我的 uitextview 在用户双击它时可编辑。 但在我的代码中它只能工作一次。隐藏键盘后双击停止像我想要的那样工作。它只显示“复制并定义”弹出窗口,如果我第二次尝试...... 也许“t
对于学校项目,我必须在 JList 上使用 ListSelectionListener(LSL)。我知道 LSL 会响应鼠标单击和鼠标释放。但对于该项目,我必须让它响应双击。有没有办法让 LSL 对此
当尝试通过双击从列表中选择项目时,它会为两个列表选择一次,但在单击选择后!!! listScrollPanel.setViewportView(categoryList); subCa
我读过这个How to distinguish between mouseReleaseEvent and mousedoubleClickEvent on QGrapnhicsScene还有这个Di
我有两个列表与 jQuery UI 中的connectedSortable 连接,但我想添加一个功能,能够双击一个项目并将其移动到另一个列表,但我真的不知道如何去做。 最佳答案 $j('#list
我正在使用 DevExpress xtraScheduler 10.2 如何处理 xtraScheduler 中的双击事件(仅在约会而非单元格上)? 我不想显示任何 appointmentedit 表
在这方面遇到了一些麻烦。所以我的公司想要应用程序的左抽屉菜单。具体来说,菜单的控件也附加在每一行中。即每一行都有单独的订单号和附加的操作按钮。单击“操作”按钮时,抽屉会打开以执行各种操作。现在的问题是
我尝试打开一个 UIAlertView,其中有两个 textfield 以及我选择的单元格中的文本。我使用这段代码: -(void)tableView:(UITableView *)tableView
以下是我的代码;我没有被 didDoubleTapMap 解雇。 UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]
所以我有一个表单,双击一个字段会弹出一个自定义模式窗口。模态窗口上的“保存”和“取消”按钮具有调用模态窗口层上的hide() 的“单击”事件。然而,我们的一些用户自然会双击东西。双击保存或取消按钮会触
我正在为 Google 地球开发此解决方案。我有一个标题,其中包含使用 CSS 创建的按钮,单击这些按钮会触发 KML 的加载。我遇到的问题是,如果用户再次单击该按钮,它会再次加载相同的 KML。我需
当我双击 ListView 项目时,我收到了 DoubleTapped 事件。 但我不确定如何获取执行点击的所选项目。ListView.Selecteditem 没有给我点击的项目。 请帮忙。 最佳答
我目前有一个 UISwitch,它在打开和关闭时分别递增和递减一个计数器。 当计数器为 0 时,计数器不会递减。从功能上讲,这工作得很好,但是我注意到一个错误,想知道是否有人遇到过这个问题。 本质上,
我试图找出如何处理鼠标左键(或任何)双击。但是我找不到任何关于它的信息。 有人能帮帮我吗?我不想编写自己的双击处理程序。 GLFW_REPEAT 不适用于鼠标按钮。 最佳答案 编写自己的双击处理程序有
我想使用 GestureDetector 的 tap 方法检测 libgdx 中的双击。手势监听类。过去两天我在网上搜索过,但找不到如何操作的示例。我知道该方法有一个“计数”变量,但我不知道如何使用它
如何识别 UIButton 上的双击? 最佳答案 为控件事件UIControlEventTouchDownRepeat添加一个target-action,只有当touch的tapCount为2时才做a
我是一名优秀的程序员,十分优秀!