Commit 6f107177 by BellCodeEditor

save project

parent 94175e12
Showing with 15 additions and 4 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
...@@ -22,6 +22,8 @@ my_fort=pygame.font.Font("neuropol.ttf",18) ...@@ -22,6 +22,8 @@ my_fort=pygame.font.Font("neuropol.ttf",18)
setheading="right" setheading="right"
shake_head=right shake_head=right
score=0 score=0
apple_x=360
apple_y=300
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:
...@@ -48,13 +50,21 @@ while True: ...@@ -48,13 +50,21 @@ while True:
y-=30 y-=30
else : else :
y+=30 y+=30
score+=score+10 if apple_x==x and apple_y==y:
num1=random.randint(1,22)
num2=random.randint(1,16)
apple_x=num1*30-30
apple_y=num2*30-30
score+=10
else:
head.pop(0)
if x<0 or x>630 or y<0 or y>450: if x<0 or x>630 or y<0 or y>450:
exit() exit()
head.append((x,y)) head.append((x,y))
head.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇画上去 # 将贪吃蛇画上去
...@@ -69,7 +79,7 @@ while True: ...@@ -69,7 +79,7 @@ while True:
text=my_fort.render(info,True,(0,0,0)) text=my_fort.render(info,True,(0,0,0))
screen.blit(text,(540,10)) screen.blit(text,(540,10))
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (apple_x, apple_y))
# 刷新画面 # 刷新画面
T.tick(3) T.tick(3)
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