Commit d024a2e0 by BellCodeEditor

save project

parent babae1f8
Showing with 14 additions and 6 deletions
...@@ -27,7 +27,7 @@ apple_y = 300 # 苹果纵坐标 ...@@ -27,7 +27,7 @@ apple_y = 300 # 苹果纵坐标
setheading = "right" setheading = "right"
snake_head = right snake_head = right
score = 0 score = 0
v=6
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,18 +56,26 @@ while True: ...@@ -56,18 +56,26 @@ while True:
y -= 30 y -= 30
else: else:
y += 30 y += 30
position.append((x, y))
for o in position:
a,b=o
if a==x and b==y:
exit()
position.append((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 = 30*num1-30 # 苹果的x坐标 apple_x = 30*num1-30 # 苹果的x坐标
apple_y = 30*num2-30 apple_y = 30*num2-30
score+=10 # 苹果的y坐标 score+=10
v+=1
# 苹果的y坐标
else: else:
position.pop(0) position.pop(0)
if x>=630 or x<0 or y>=450 or y<0 or score==100:
if x>=660 or x<0 or y>=480 or y<0 or score==100:
exit() exit()
# 将背景图画上去 # 将背景图画上去
...@@ -87,4 +95,4 @@ while True: ...@@ -87,4 +95,4 @@ while True:
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(15) FPSCLOCK.tick(v)
\ 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