Commit 81ed9f81 by BellCodeEditor

save project

parent cb434e38
Showing with 9 additions and 1 deletions
...@@ -22,6 +22,7 @@ body = pygame.image.load('body.png') ...@@ -22,6 +22,7 @@ body = pygame.image.load('body.png')
left = pygame.image.load("left.png") left = pygame.image.load("left.png")
up = pygame.image.load("up.png") up = pygame.image.load("up.png")
down = pygame.image.load('down.png') down = pygame.image.load('down.png')
ziti = pygame.font.Font('neuropol.ttf',18)
snake_head=right snake_head=right
...@@ -31,7 +32,7 @@ snake_head=right ...@@ -31,7 +32,7 @@ snake_head=right
score=0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -66,6 +67,7 @@ while True: ...@@ -66,6 +67,7 @@ while True:
shenti.append((x,y)) shenti.append((x,y))
if x==apple_x and y==apple_y: if x==apple_x and y==apple_y:
score+=10
num1=apple_x=random.randint(1,22) num1=apple_x=random.randint(1,22)
num2=apple_y=random.randint(1,16) num2=apple_y=random.randint(1,16)
apple_x=num1*30-30 apple_x=num1*30-30
...@@ -79,10 +81,15 @@ while True: ...@@ -79,10 +81,15 @@ while True:
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(shenti)-1): for i in range(len(shenti)-1):
screen.blit(body,shenti[i]) screen.blit(body,shenti[i])
info = "score:"+str(score)
text = ziti.render(info,True,(0,0,0))
screen.blit(text,(540,10))
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
time.tick(3) time.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