大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
import sys, pygame
from pygame.locals import *
from random import randrange
up =lambda x:(x[0]-1,x[1])
down = lambda x :(x[0]+1,x[1])
left = lambda x : (x[0],x[1]-1)
right = lambda x : (x[0],x[1]+1)
tl = lambda x :x<3 and x+1 or 0
tr = lambda x :x==0 and 3 or x-1
dire = [up,left,down,right]
move = lambda x,y:[y(x[0])]+x[:-1]
grow = lambda x,y:[y(x[0])]+x
s = [(5,5),(5,6),(5,7)]
d = up
food = randrange(0,30),randrange(0,40)
FPSCLOCK=pygame.time.Clock()
pygame.init()
pygame.display.set_mode((800,600))
pygame.mouse.set_visible(0)
screen = pygame.display.get_surface()
screen.fill((0,0,0))
times=0.0
while True:
time_passed = FPSCLOCK.tick(30)
if times>=150:
times =0.0
s = move(s,d)
else:
times +=time_passed
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
if event.type == KEYDOWN and event.key == K_UP:
s = move(s,d)
if event.type == KEYDOWN and event.key == K_LEFT:
d=dire[tl(dire.index(d))]
if event.type == KEYDOWN and event.key == K_RIGHT:
d=dire[tr(dire.index(d))]
if s[0]==food:
s = grow(s,d)
food =randrange(0,30),randrange(0,40)
if s[0] in s[1:] or s[0][0]<0 or s[0][0]
>= 30 or s[0][1]<0 or
s[0][1]>=40:
break
screen.fill((0,0,0))
for r,c in s:
pygame.draw.rect(screen,(255,0,0),(c*20,r*20,20,20))
pygame.draw.rect(screen,(0,255,0),(food[1]*20,food[0]*20,20,20))
pygame.display.update()
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/169555.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...