Commit 79fea323 by BellCodeEditor

auto save

parent e3f1b147
Showing with 13 additions and 6 deletions
......@@ -21,9 +21,10 @@ x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)]
#
setheading = "right"
snake_head = righ
snake_head = right
#设置记录苹果坐标的apple_x,apple_y
apple_x=360
apple_y=300
while True:
for event in pygame.event.get():
......@@ -56,9 +57,14 @@ while True:
position.append((x, y))
#贪吃蛇吃到苹果,苹果被吃后随机出现在窗口其他位置
#判断贪吃蛇蛇头的坐标位置与苹果的坐标位置是否一致
apple_x=?
apple_y=
if x==apple_x and y==apple_y:
#num1(记录苹果横排所在的格子)随机数
#num2(记录苹果竖排所在的格子)随机数
num1=random.randint(0,22)
num2=random.randint(0,16)
apple_x=num1*30-30
apple_y=num2*30-30
else:
position.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
......@@ -69,7 +75,7 @@ while True:
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (, ))
screen.blit(food, (apple_x, apple_y))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
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