Commit 3632b0bd by BellCodeEditor

save project

parent 4c9a5e18
Showing with 20 additions and 2 deletions
......@@ -5,6 +5,8 @@ import random
# 初始化pygame,为使用硬件做准备
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -23,6 +25,9 @@ position = [(180, 90), (180, 120), (210, 120), (x, y)]
apple_x=360
apple_y=300
score=0
setheading = "right"
snake_head = right
......@@ -56,10 +61,20 @@ while True:
y += 30
position.append((x, y))
if x > 630 or y> 450 or x<0 or y<0:
exit()
if x==apple_x and y==apple_y:
apple_x=random.randint(0,660)
apple_y=random.randint(0,480)
num1=random.randint(1,22)
num2=random.randint(1,16)
apple_x=num1*30-30
apple_y=num2*30-30
score=score+1
else:
position.pop(0)
myFont=pygame.font.Font('neuropol.ttf',18)
text=myFont.render('score:'+str(score),True,(0,0,0))
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
......@@ -70,6 +85,8 @@ while True:
# 将果实画上去
screen.blit(food, (apple_x, apple_y))
screen.blit(text, (540, 5))
# 刷新画面
pygame.display.update()
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