Commit 29211ae5 by BellCodeEditor

save project

parent 82dc80c6
Showing with 8 additions and 1 deletions
import pygame import pygame
import random import random
from random import randint
from pygame import locals from pygame import locals
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
...@@ -17,7 +18,9 @@ body = pygame.image.load('body.png') # 身体 ...@@ -17,7 +18,9 @@ body = pygame.image.load('body.png') # 身体
left = pygame.image.load('left.png') # 头 朝左 left = pygame.image.load('left.png') # 头 朝左
up = pygame.image.load('up.png') # 头 朝上 up = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下 down = pygame.image.load('down.png') # 头 朝下
font = pygame.font.Font("neuropol.ttf",50)
score=0
r,g,b=0,0,0
x, y = 240, 120 x, y = 240, 120
position = [(180, 90), (180, 120), (210, 120), (x, y)] position = [(180, 90), (180, 120), (210, 120), (x, y)]
a2x=random.randint(1,21) a2x=random.randint(1,21)
...@@ -28,6 +31,7 @@ setheading = "right" ...@@ -28,6 +31,7 @@ setheading = "right"
snake_head = right snake_head = right
while True: while True:
r,g,b=randint(0,255),randint(0,255),randint(0,255)
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
...@@ -64,6 +68,7 @@ while True: ...@@ -64,6 +68,7 @@ while True:
apple_x=30*a2x apple_x=30*a2x
apple_y=30*a2y apple_y=30*a2y
position.append((x,y)) position.append((x,y))
score+=10
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去 # 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1]) screen.blit(snake_head, position[-1])
...@@ -72,6 +77,8 @@ while True: ...@@ -72,6 +77,8 @@ while True:
screen.blit(body, position[i]) screen.blit(body, position[i])
# 将果实画上去 # 将果实画上去
text = font.render("Score:"+str(score),True,(r,g,b))
screen.blit(text,(randint(0,6),randint(0,5)))
screen.blit(food, (apple_x, apple_y)) screen.blit(food, (apple_x, apple_y))
# 刷新画面 # 刷新画面
......
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