Commit 96635464 by BellCodeEditor

save project

parent 3aafc75a
Showing with 10 additions and 7 deletions
......@@ -3,7 +3,8 @@ from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
l=''
m=''
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -55,11 +56,12 @@ while True:
y += 30
position.append((x, y))
if x==apple_x and y==apple_y:
apple_x=random.randint(0,21)
apple_x=random.randint(0,15)
l=apple_x*30
m=apple_y*30
else position.pop(0):
a=random.randint(0,22)
b=random.randint(0,16)
apple_x=a*30-30
apple_y=b*30-30
else:
position.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
......@@ -69,7 +71,7 @@ while True:
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food,(l,m))
screen.blit(food,(apple_x,apple_y))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(10)
\ 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