Commit f8ddb4ff by BellCodeEditor

auto save

parent 0390d315
Showing with 25 additions and 5 deletions
......@@ -22,7 +22,7 @@ position = [(180, 90), (180, 120), (210, 120), (x, y)]
apple_x,apple_y=360,300
setheading = "right"
snake_head = right
score=0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -51,12 +51,23 @@ while True:
y -= 30
else:
y += 30
# 吃掉水果身体变长
if x==apple_x and y==apple_y:
num_x
apple_x=random.randint(30,1800)%30
apple_y=random.randint(30,14400)%30
num_x=random.randint(1,22)
num_y=random.randint(1,16)
apple_x=num_x*30
apple_y=num_y*30
score+=1
else:
position.pop(0)
#贪吃蛇撞墙停止
if x<0 or x>630 or y<0 or y>450:
font1=pygame.font.Font('neuropol.ttf',25)
text1=font.render("游戏失败",True,(0,0,0))
screen.blit(text,(200,200))
break
position.append((x, y))
position.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
......@@ -67,6 +78,14 @@ while True:
# 将果实画上去
screen.blit(food, (apple_x, apple_y))
# 绘制分数
# 1.载入字体
font=pygame.font.Font('neuropol.ttf',18)
# 2.设置字体文字
text=font.render("Score:"+str(score),True,(0,0,0))
# 3.渲染
screen.blit(text,(400,0))
# 刷新画面
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