Commit 96635464 by BellCodeEditor

save project

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