Commit 7073a663 by BellCodeEditor

auto save

parent 845298e8
Showing with 13 additions and 4 deletions
...@@ -55,7 +55,7 @@ while True: ...@@ -55,7 +55,7 @@ while True:
else: else:
y += 30 y += 30
position.append((x, y)) position.append((x, y))
position.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去 # 将贪吃蛇的头画上去
...@@ -66,11 +66,20 @@ while True: ...@@ -66,11 +66,20 @@ while True:
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
#监测蛇身蛇尾
for i in range(len(position)-1):
if position[i] == (x,y):
exit()
#随机刷新果实 #随机刷新果实
if x == apple_x and y == apple_y: if x == apple_x and y == apple_y:
apple_x = 30 * random.randint(0,22) for i in range(len(position)-1):
apple_y = 30 * random.randint(0,16) apple_x = 30 * random.randint(0,21)
apple_y = 30 * random.randint(0,15)
while (apple_x,apple_y) == position[i]:
apple_x = 30 * random.randint(0,21)
apple_y = 30 * random.randint(0,15)
else:
position.pop(0)
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
......
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