From 8ec2c7e4f3cfbf8e7a5dc212fae42fa0a5f4ec73 Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Tue, 25 Jan 2022 19:46:31 +0800 Subject: [PATCH] save project --- snake.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/snake.py b/snake.py index 537316e..2bbb2d1 100644 --- a/snake.py +++ b/snake.py @@ -1,5 +1,6 @@ import pygame from pygame import locals +import random # 初始化pygame,为使用硬件做准备 pygame.init() @@ -41,6 +42,9 @@ 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": -- libgit2 0.25.0