Commit 85e005d6 by BellCodeEditor

save project

parent 24e404e7
Showing with 12 additions and 2 deletions
......@@ -30,12 +30,14 @@ setheading = "right"
snake_head = right
while True:
a=random.randint(0,10)
a=random.randint(2,5)
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
print("您已退出")
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and setheading != "left":
setheading = 'right'
......@@ -66,6 +68,15 @@ while True:
score+=10
else:
position.pop(0)
if x<0 or x>630 or y<0 or y>450:
print('您撞到了边框')
exit()
if position[-1] in position[:-1]:
print('您撞到了自己')
exit()
# if (apple_x,apple_y) in position[:len[position]-2]:
# apple_x=(random.randint(0,630))//30*30
# apple_y=(random.randint(0,450))//30*30
......@@ -76,7 +87,6 @@ while True:
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (apple_x, apple_y))
info='Score:'+str(score)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment