Commit 5971dd2b by BellCodeEditor

auto save

parent b6e3b9aa
import pygame
import random
from pygame import locals
pygame.init()#初始化
background=pygame.image.load("bg.png")
right=pygame.image.load("right.png")
body=pygame.image.load("body.png")
food=pygame.image.load("apple.png")
left=pygame.image.load("left.png")
up=pygame.image.load("up.png")
down=pygame.image.load("down.png")
screen=pygame.display.set_mode((660,480))
x,y=240,120
position=[(180,90),(180,120),(210,120),(x,y)]
apple_x=360#苹果横坐标
apple_y=360#苹果纵坐标
FP=pygame.time.Clock()
settheading="right"
snake_head=right
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 settheading !="left":
settheading="right"
snake_head=right
if event.key==locals.K_LEFT and settheading !="right":
settheading="left"
snake_head=left
if event.key==locals.K_UP and settheading !="down":
settheading="up"
snake_head=up
if event.key==locals.K_DOWN and settheading !="up":
settheading="down"
snake_head=down
if settheading=="right":
x=x+30
elif settheading=="left":
x=x-30
elif settheading=="up":
y=y-30
else:
y=y+30
position.append((x,y))
if x==apple_x and y==apple_y:
#apple_x=random.randint(0,660)
#apple_y=random.randint(0,480)
a=random.randint(1,22)
b=random.randint(1,16)
apple_x=(a-1)*30
apple_y=(b-1)*30
position.pop(0)
screen.blit(background,(0,0))
screen.blit(snake_head,position[-1])
for i in range(len(position)-1):
screen.blit(body,position[i])
screen.blit(food,(apple_x,apple_y))
#screen.blit(body,(210,120))
#screen.blit(body,(180,120))
#screen.blit(body,(180,90))
pygame.display.update()
FP.tick(1)
print(z)
\ No newline at end of file
apple.png

2.05 KB

bg.png

22.5 KB

body.png

1.4 KB

# 报菜名
# 悟空和诺依到了一家特色餐馆,这家餐馆最大的特色就是有个自动报菜名机器人
# 通常它会自动说出今天的前菜有哪些汤有哪些主菜有哪些等等~
# 可是今儿它有些bug产生的结果很奇怪,你可以检查出来么?
today_menu={'前菜':{'熏鲢鱼':20,'生蚝':20,'面包':10},
'汤':{'玉米浓汤':15,'蔬菜汤':15,'海鲜汤':15},
'主菜':{'鱼':40,'虾':30,'蟹':20,'贝壳类':20},
'间菜':{'牛扒':25,'煨菜':25,'肉排':30},
"烧烤和沙拉":{'需要':15,'不需要':0},
'甜品':{'可丽露':20,'优格吐司':15,'蓝莓松饼':20}
}
for k,v in today_menu.items():
print('今日' + k + '有:')
for i in v:
print(i,end=' ') #依次告诉客人今天的各类菜有哪些选择
print()
\ No newline at end of file
down.png

2.01 KB

left.png

2.07 KB

import pygame
from pygame import locals
pygame.init()#初始化
background=pygame.image.load("bg.png")
right=pygame.image.load("right.png")
body=pygame.image.load("body.png")
food=pygame.image.load("apple.png")
screen=pygame.display.set_mode((660,480))
x,y=240,120
position=[(180,90),(180,120),(210,120),(x,y)]
FP=pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type==locals.QUIT:
exit()
x=x+30
position.append((x,y))
position.pop(0)
screen.blit(background,(0,0))
screen.blit(right,position[-1])
for i in range(len(position)-1):
screen.blit(body,position[i])
screen.blit(food,(360,300))
#screen.blit(body,(210,120))
#screen.blit(body,(180,120))
#screen.blit(body,(180,90))
pygame.display.update()
FP.tick(1)
\ No newline at end of file
File added
right.png

2.05 KB

up.png

2.05 KB

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