Commit d3a1e5cc by BellCodeEditor

save project

parent c83fae5f
Showing with 15 additions and 7 deletions
import pygame
from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
......@@ -19,6 +20,8 @@ right_a='right'
right_b=right
x,y=240, 120
a_b=[(120,120),(150,120),(180,120),(x,y)]
apple_x=360
apple_y=300
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -40,16 +43,20 @@ while True:
if right_a=='light':
x+=30
if right_a=='left':
elif right_a=='left':
x-=30
if right_a=='up':
elif right_a=='up':
y-=30
if right_a=='down':
else :
y+=30
x+=30
a_b.append((x,y))
a_b.pop(0)
if x==apple_x and y==apple_ty:
numder1_x=random.randint(1,22)
numder2_y=random.randint(1,16)
apple_x=numder1*30-30
apple_y=numder2*30-30
else:
a_b.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
......@@ -60,7 +67,7 @@ while True:
# 将果实画上去
screen.blit(food, (360, 300))
screen.blit(food, (apple_x, apple_y))
# 刷新画面
pygame.display.update()
r.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