From 00acb471ae7bd704b8609efa5bc54dff36aebb0e Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Wed, 4 Aug 2021 19:36:53 +0800 Subject: [PATCH] save project --- snake.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/snake.py b/snake.py index 537316e..64f2e7c 100644 --- a/snake.py +++ b/snake.py @@ -1,6 +1,6 @@ import pygame from pygame import locals - +import random # 初始化pygame,为使用硬件做准备 pygame.init() @@ -53,9 +53,12 @@ while True: y += 30 position.append((x, y)) position.pop(0) - # 将背景图画上去 + if apple_x==x and apple_y==y: + apple_x=random.randint(0,21) + apple_x=random.randint(0,15) + apple_x=apple_x*30 + apple_y=apple_y*30 screen.blit(background, (0, 0)) - # 将贪吃蛇的头画上去 screen.blit(snake_head, position[-1]) # 将贪吃蛇的身体画上去 for i in range(len(position)-1): -- libgit2 0.25.0