Commit 2ddd98e1 by BellCodeEditor

save project

parent 0d0e17be
Showing with 12 additions and 3 deletions
...@@ -25,6 +25,8 @@ setheading = "right" ...@@ -25,6 +25,8 @@ setheading = "right"
snake_head = right snake_head = right
apple_x = random.randint(0,21)*30 apple_x = random.randint(0,21)*30
apple_y = random.randint(0,15)*30 apple_y = random.randint(0,15)*30
my_font = pygame.font.Font('neuropol.ttf',15)
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:
...@@ -56,8 +58,11 @@ while True: ...@@ -56,8 +58,11 @@ while True:
if (x,y) == (apple_x,apple_y): if (x,y) == (apple_x,apple_y):
apple_x = random.randint(0,21)*30 apple_x = random.randint(0,21)*30
apple_y = random.randint(0,15)*30 apple_y = random.randint(0,15)*30
score += 1
else: else:
position.pop(0) position.pop(0)
if x<0 or x>630 or y<0 or y>450:
exit()
position.append((x, y)) position.append((x, y))
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
...@@ -66,9 +71,13 @@ while True: ...@@ -66,9 +71,13 @@ while True:
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body, position[i]) screen.blit(body, position[i])
if position[i] == (x,y):
exit()
text = 'Score:'+str(score)
info = my_font.render(text,True,(0,0,0))
screen.blit(info,(550,10))
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(3+score/5)
\ No newline at end of file \ 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