Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

Administrator / pygame_lesson3_diy4

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit d85cc730 authored 3 years ago by BellCodeEditor's avatar BellCodeEditor
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

save project

parent f806a5c2 c100713l1354p256a13985/wx459954
Hide whitespace changes
Inline Side-by-side
Showing with 9 additions and 2 deletions
  • snake.py
snake.py
View file @ d85cc730
import pygame
from pygame import locals
import random
import time
# 初始化pygame,为使用硬件做准备
pygame.init()
......@@ -18,6 +19,7 @@ left = pygame.image.load('left.png') # 头 朝左
up = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下
w=pygame.font.Font('neuropol.ttf',18)
ff=pygame.font.Font('neuropol.ttf',70)
x, y = 240, 120
s,b=360,180
position = [(180, 90), (180, 120), (210, 120), (x, y)]
......@@ -64,6 +66,7 @@ while True:
position.pop(0)
# 将背景图画上去
qq='s:'+str(a)
xx='Game Over'
screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去
screen.blit(snake_head, position[-1])
......@@ -72,8 +75,12 @@ while True:
screen.blit(ddd,(0,0))
for i in range(len(position)-1):
screen.blit(body, position[i])
if x<0 or x>630 or y<0 or y>450
if x<0 or x>630 or y<0 or y>450 or ((x,y) in position[:-1]):
sss=ff.render(xx,True,(0,0,0))
screen.blit(sss,(60,60))
pygame.display.flip()
time.sleep(3)
exit()
# 将果实画上去
screen.blit(food, (s,b))
# 刷新画面
......
This diff is collapsed. Click to expand it.
  • Write
  • Preview
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