From b016da995dced099580615711cd7b1097d379235 Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Sun, 31 Jan 2021 16:00:39 +0800 Subject: [PATCH] save project --- snake.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/snake.py b/snake.py index 6e6fd05..90122c8 100644 --- a/snake.py +++ b/snake.py @@ -42,9 +42,8 @@ while True: if event.key == locals.K_DOWN and setheading != "up": setheading = 'down' snake_head = down - if x==apple_x and y==apple_y: - apple_x=random.randint(0,660) - apple_y=random.randint(0,480) + + # 设置贪吃蛇的头部坐标 if setheading == "right": x += 30 @@ -58,8 +57,12 @@ while True: if x==apple_x and y==apple_y: apple_x=random.randint(0,660) apple_y=random.randint(0,480) - - position.pop(0) + num1=random.randint(1,22) + num2=random.randint(1,16) + apple_x=30*num1-30 + apple_y=30*num2-30 + else: + position.pop(0) # 将背景图画上去 screen.blit(background, (0, 0)) # 将贪吃蛇的头画上去 -- libgit2 0.25.0