Commit e1f3f450 by BellCodeEditor

auto save

parent 2f104332
Showing with 8 additions and 2 deletions
...@@ -26,6 +26,8 @@ snake_head = right ...@@ -26,6 +26,8 @@ snake_head = right
apples_x=360 apples_x=360
apples_y=300 apples_y=300
num1=0
num2=0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -46,8 +48,10 @@ while True: ...@@ -46,8 +48,10 @@ while True:
snake_head = down snake_head = down
if x==apples_x and y==apples_y: if x==apples_x and y==apples_y:
apples_x=random.randint(0,660) num1=random.randint(1,22)
apples_y=random.randint(0,480) num2=random.randint(1,16)
apples_x=num1*30-30
apples_y=num2*30-30
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if setheading == "right": if setheading == "right":
...@@ -59,6 +63,8 @@ while True: ...@@ -59,6 +63,8 @@ while True:
else: else:
y += 30 y += 30
position.append((x, y)) position.append((x, y))
if x==apples_x and y==apples_y:
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
......
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