Commit dc90dbc7 by BellCodeEditor

auto save

parent 01beaadc
Showing with 19 additions and 60 deletions
import pygame
from pygame import locals
# 初始化pygame,为使用硬件做准备
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
asdfk=pygame.time.Clock()
# 背景
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
down = pygame.image.load('down.png')
left = pygame.image.load('left.png')
up = pygame.image.load('up.png')
x=240
y=120
qwer=[(210,120),(180,120),(180,90),(x,y)]
qwert='right'
qaz=right
import random
import turtle
c=turtle.Screen()
d=turtle.Pen()
a=random.randint(0,100)
q=0
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and qwert != 'left':
qwert = 'right'
qaz=right
elif event.key == locals.K_UP and qwert != 'down':
qwert = 'up'
qaz=up
elif event.key == locals.K_LEFT and qwert != 'right':
qwert = 'left'
qaz=left
elif event.key == locals.K_DOWN and qwert != 'up':
qwert = 'down'
qaz=down
if qwert == 'right' :
x+=30
elif qwert == 'up':
y-=30
elif qwert == 'left':
x-=30
elif qwert == 'down':
y+=30
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
qwer.append((x,y))
qwer.pop(0)
screen.blit(qaz, (x,y))
b=c.textinput('猜数字','输入一个数')
d.clear()
b=int(b)
if b==a:
d.write('yes',font=('Times',30,'normal'))
elif b<a:
for i in range(len(qwer)-1):
screen.blit(body,qwer[i])
pygame.display.update()
asdfk.tick(5)
\ No newline at end of file
d.write('big',font=('Times',30,'normal'))
q+=1
elif b>a:
d.write('s',font=('Times',30,'normal'))
q+=1
turtle.done()
\ 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