
Lv.1
卧薪藏胆某人
签名:一边期盼吉吉喵给权限一边在不属于我的地图上写代码
在 【Python作品分享】贪吃蛇V0.9【求助帖】 中回复
import pygame, sys, time, random
from pygame.key import *
pygame.init()
sceen = pygame.display.set_mode((500, 500))
sceen.fill((255, 255, 255))
pygame.draw.rect(sceen, (0, 0, 0), (0, 0, 500, 500), 100)
pygame.display.flip()
pygame.display.set_caption('经典贪吃蛇游戏即将开始')
class draw:#用来画画的类 #20×20像素为一个格子
def hand(x, y, direction):#画头
pygame.draw.rect(sceen, (85, 85, 85), (x * 20 + 51, y * 20 + 51, 18, 18), 0)#画头
if direction == 'up':#画眼
pygame.draw.rect(sceen, (255, 255, 255), (x * 20 + 55, y * 20 + 55, 3, 3))
pygame.draw.rect(sceen, (255, 255, 255), (x * 20 + 62, y * 20 + 55, 3, 3))
elif direction == 'down':
pygame.draw.rect(sceen, (255, 255, 255), (x * 20 + 55, y * 20 + 62, 3, 3))
pygame.draw.rect(sceen, (255, 255, 255), (x * 20 + 62, y * 20 + 62, 3, 3))
elif direction == 'left':
pygame.draw.rect(sceen, (255, 255, 255), (x * 20 + 55, y * 20 + 55, 3, 3))
pygame.draw.rect(sceen, (255, 255, 255), (x * 20 + 55, y * 20 + 62, 3, 3))
elif direction == 'right':
pygame.draw.rect(sceen, (255, 255, 255), (x * 20 + 62, y * 20 + 55, 3, 3))
pygame.draw.rect(sceen, (255, 255, 255), (x * 20 + 62, y * 20 + 62, 3, 3))
def body(x, y):#画蛇身
pygame.draw.rect(sceen, (170, 170, 170), (x * 20 + 51, y * 20 + 51, 18, 18), 0)
def food(x, y):#画食物
pygame.draw.circle(sceen, (170, 170, 170), (x * 20 + 60, y * 20 + 60), 8, 0)
def mobile(direction):#移动整条蛇
global snaks, revious#revious变量:用来存储那段“消失”的坐标,可以说是备份,或者电脑系统里的“回收站”
if direction == 'up':
snaks.insert(0, (snaks[0][0], snaks[0][1] - 1))
revious = snaks.pop()
elif direction == 'down':
snaks.insert(0, (snaks[0][0], snaks[0][1] + 1))
revious = snaks.pop()
elif direction == 'left':
snaks.insert(0, (snaks[0][0] - 1, snaks[0][1]))
revious = snaks.pop()
elif direction == 'right':
snaks.insert(0, (snaks[0][0] + 1, snaks[0][1]))
revious = snaks.pop()
snaks = [(10, 9)]#蛇的坐标们 #第一项是头,然后是身子们
food = (10, 9)#食物的坐标
while food in snaks:#避免食物和蛇重合
food = (random.randint(0, 19), random.randint(0, 19))
direction = 'left'#方向,用来画头和移动
score = 0#得分
time.sleep(1)
pygame.display.set_caption('3')
time.sleep(1)
pygame.display.set_caption('2')
time.sleep(1)
pygame.display.set_caption('1')
time.sleep(1)
pygame.display.set_caption('Go!')
time.sleep(1)
while True:
for event in pygame.event.get():
if event == pygame.QUIT:
sys.exit()
sceen.fill((255, 255, 255))
pygame.draw.rect(sceen, (0, 0, 0), (0, 0, 500, 500), 100)
mobile(direction)
if food == snaks[0]:
score += 1
snaks.append(revious)
while food in snaks:
food = (random.randint(0, 19), random.randint(0, 19))
draw.food(food[0], food[1])
draw.hand(snaks[0][0], snaks[0][1], direction)
for body in snaks[1:]:
draw.body(body[0], body[1])
pygame.display.flip()
if snaks[0] in snaks[1:]:
pygame.display.set_caption('你撞到了自己,失败了。')
time.sleep(1)
pygame.display.set_caption('本次游戏你得到了' + str(score) + '分。')
time.sleep(1)
sys.exit()
if snaks[0][0] < 0 or snaks[0][0] > 19 or snaks[0][1] < 0 or snaks[0][1] > 19:
pygame.display.set_caption('你撞到了墙,失败了。')
time.sleep(1)
pygame.display.set_caption('本次游戏你得到了' + str(score) + '分。')
time.sleep(1)
sys.exit()
if get_pressed()[pygame.K_UP]:
direction = 'up'
if get_pressed()[pygame.K_DOWN]:
direction = 'down'
if get_pressed()[pygame.K_LEFT]:
direction = 'left'
if get_pressed()[pygame.K_RIGHT]:
direction = 'right'
pygame.display.set_caption('得分:' + str(score))
time.sleep(0.2)
咋样
2020-07-08T22:43:05 点赞:0
在 【从扫雷开始的kitten进阶教程】巧建地图————二维数组的构建与应用 中回复
我还以为你要叫我们C呢!
int list[9][9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}2020-07-15T10:47:39 点赞:0
在 【代码岛3.0暑期更新!】自定义装备!传送带以及新一轮编辑器发放! 中回复
一,捉迷藏游戏
二,
3,https://box3create.codemao.cn/games/f700bd57358eed9d1cb0
2020-07-31T15:31:37 点赞:0
在 【讨论】距离你左手最近的东西是? 中回复
最近的东东 = {'最大尺度':'宇宙','小一点':'本超星系团','再小一点':'本星系团','小到星系':'银河系','又小了一点':'猎户旋臂','小到恒星系':'太阳系','小到行星':'地球','变小了很多':'亚洲','还要小一些':'中国','还小一点':'湖北','作者的手快麻了':'荆州','真的要麻了':'沙市','又小了很多':'我家','作者快找不到词了':'鼠标','进入微观世界':'地球大气层里的空气','再小一丢丢':'氢,氦,氧……','实在太小了':'氢原子,氧原子……','真的不能再小了':'原子核,电子','小小小!':'中子,质子','求放过':'上夸克,下夸克':'终于写完了……':'空间(虚无)'}2020-07-31T22:11:02 点赞:1
在 奇葩文字 太奇葩 中回复
㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿㍿
2020-07-31T22:13:22 点赞:0
在 建议源码编辑器5.0加入这些积木 (控制积木) 中回复
一定要加:1,变量就是变量,何必指定类型呢?
2,字典,序列,类,对象,一定要有!
3,正序云排行榜!
2020-07-31T23:24:42 点赞:0