diff --git a/snake.py b/snake.py index 0b3d89a..8cccda1 100644 --- a/snake.py +++ b/snake.py @@ -22,12 +22,12 @@ x, y = 240, 120 position = [(180, 90), (180, 120), (210, 120), (x, y)] apple_Xlst=[] apple_Ylst=[] -apple_X=360 -apple_Y=240 for i in range(0,661,30): apple_Xlst.append(i) for j in range(0,481,30): apple_Ylst.append(j) +apple_X=choice(apple_Xlst) +apple_Y=choice(apple_Ylst) setheading = "right" snake_head = right @@ -67,16 +67,15 @@ while True: y += 30 position.append((x, y)) position.pop(0) - # 将背景图画上去 + # 将背景图画上去 screen.blit(background, (0, 0)) + # 将果实画上去 + screen.blit(food, (apple_X,apple_Y)) # 将贪吃蛇的头画上去 screen.blit(snake_head, position[-1]) # 将贪吃蛇的身体画上去 for i in range(len(position)-1): screen.blit(body, position[i]) - - # 将果实画上去 - screen.blit(food, (apple_X,apple_Y)) # 刷新画面 pygame.display.update() FPSCLOCK.tick(3) \ No newline at end of file