Commit 8265d0b0 by BellCodeEditor

save project

parent d5739bd2
Showing with 16 additions and 1 deletions
import pygame import pygame
from random import choice
from pygame import locals from pygame import locals
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
...@@ -19,6 +20,14 @@ down = pygame.image.load('down.png') # 头 朝下 ...@@ -19,6 +20,14 @@ down = pygame.image.load('down.png') # 头 朝下
x, y = 240, 120 x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)] 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)
setheading = "right" setheading = "right"
snake_head = right snake_head = right
...@@ -42,6 +51,11 @@ while True: ...@@ -42,6 +51,11 @@ while True:
setheading = 'down' setheading = 'down'
snake_head = down snake_head = down
if x==apple_X and y==apple_Y:
apple_X=choice(apple_Xlst)
apple_Y=choice(apple_Ylst)
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if setheading == "right": if setheading == "right":
x += 30 x += 30
...@@ -62,7 +76,7 @@ while True: ...@@ -62,7 +76,7 @@ while True:
screen.blit(body, position[i]) screen.blit(body, position[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (apple_X,apple_Y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) 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