Commit c6d54c12 by BellCodeEditor

save project

parent 4aced13b
Showing with 6 additions and 2 deletions
...@@ -21,6 +21,7 @@ x,y = 240,120 ...@@ -21,6 +21,7 @@ x,y = 240,120
position = [(180,90)(180,120)(210,120)(x,y)] position = [(180,90)(180,120)(210,120)(x,y)]
setheading = 'right' setheading = 'right'
snake_head = right snake_head = right
score = 0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
...@@ -50,7 +51,7 @@ elif setheading == 'up': ...@@ -50,7 +51,7 @@ elif setheading == 'up':
else: else:
y +=30 y +=30
position.appent((x,y)) position.appent((x,y))
if x = apple_x and y = apple_y: if x == apple_x and y == apple_y:
num1 = random.randint(1,22) num1 = random.randint(1,22)
num2 = random.randint(1,16) num2 = random.randint(1,16)
apple_x = num1*30-30 apple_x = num1*30-30
...@@ -63,7 +64,7 @@ else: ...@@ -63,7 +64,7 @@ else:
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
screen.blit(right,position[-1]) screen.blit(snake_head,position[-1])
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body,position[i]) screen.blit(body,position[i])
# 将贪吃蛇画上去 # 将贪吃蛇画上去
...@@ -74,5 +75,7 @@ else: ...@@ -74,5 +75,7 @@ else:
screen.blit(body, (180, 90)) screen.blit(body, (180, 90))
# 将果实画上去 # 将果实画上去
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
info = "Score"+ str(score)
text = my_font.render(info,True,(0,0,0))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
\ 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