Commit e8bb276d by BellCodeEditor

save project

parent 835fbf24
Showing with 4 additions and 0 deletions
...@@ -4,6 +4,7 @@ import random ...@@ -4,6 +4,7 @@ import random
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
...@@ -26,6 +27,7 @@ setheading = "right" ...@@ -26,6 +27,7 @@ setheading = "right"
snake_head = right snake_head = right
score=0 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:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
...@@ -73,6 +75,8 @@ while True: ...@@ -73,6 +75,8 @@ while True:
apple_y=num2*30-30 apple_y=num2*30-30
else: else:
position.pop(0) position.pop(0)
if x < 0 or x > 630 or y < 0 or y > 450:
exit()
info="Score"+str(score) info="Score"+str(score)
text=my_font.render(info,True,(0,0,0)) text=my_font.render(info,True,(0,0,0))
screen.blit(text,(540,10)) screen.blit(text,(540,10))
......
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