Commit 1ac620ee by BellCodeEditor

save project

parent 1e0b2304
Showing with 8 additions and 4 deletions
......@@ -23,9 +23,10 @@ position = [(180, 90), (180, 120), (210, 120), (x, y)]
setheading = "right"
snake_head = right
score=0
apple_x=360
apple_y=300
my_font = pygame.font.Font("neuropol.ttf",24)
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
......@@ -58,6 +59,7 @@ while True:
if x == apple_x and y == apple_y:
apple_x = 30*random.randint(0,21)
apple_y = 30*random.randint(0,15)
score += 10
else:
position.pop(0)
# 将背景图画上去
......@@ -67,9 +69,11 @@ while True:
# 将贪吃蛇的身体画上去
for i in range(len(position)-1):
screen.blit(body, position[i])
info = 'Score:' + str(score)
text = my_font.render(info,True,(0,0,0))
screen.blit(text,(500,10))
# 将果实画上去
screen.blit(food, (apple_x, apple_y))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
FPSCLOCK.tick(4)
\ 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