Commit 9b7f7c43 by BellCodeEditor

save project

parent 30393b2f
Showing with 7 additions and 7 deletions
......@@ -6,7 +6,7 @@ import random
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
screen = pygame.display.set_mode((780, 570))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 背景
......@@ -29,7 +29,7 @@ snake_head = right
while True:
for event in pygame.event.get():
if event.type == locals.QUIT or x < 0 or x > 630 or y < 0 or y > 450:
if event.type == locals.QUIT :
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
......@@ -45,7 +45,7 @@ while True:
if event.key == locals.K_DOWN and setheading != "up":
setheading = 'down'
snake_head = down
if x < 0 or x > 630 or y < 0 or y > 450:
if x < 0 or x > 750 or y < 0 or y > 540:
exit()
# 设置贪吃蛇的头部坐标
......@@ -59,8 +59,8 @@ while True:
y += 30
position.append((x, y))
if x == apple_x*30-30 and y == apple_y*30-30:
apple_x = random.randint(1,22)
apple_y = random.randint(1,16)
apple_x = random.randint(1,25)
apple_y = random.randint(1,18)
score += 1
else:
position.pop(0)
......@@ -78,4 +78,4 @@ while True:
screen.blit(food, (apple_x*30-30,apple_y*30-30))
# 刷新画面
pygame.display.update()
FPSCLOCK.tick(3)
\ No newline at end of file
FPSCLOCK.tick(5)
\ 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