Lv.1
Hello, world!
在 【求助】一个python代码 中回复
首先是老鱼头说的,我的跟报错没关系
你这个方法不太对吧,
1 最好用随机数:
第一行 import random
第二行 change =["剪刀","石头","布"]
后面print ( change [random.randint(0, 2)] )
就不会稳中带皮了
2018-07-23T17:44:58 点赞:0
在 【海龟编辑器上线】可以一键装“酷”(库)的Python客户端! 中回复
技术喵,你救了我的Pygame!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2018-08-04T22:56:08 点赞:0
在 【反馈建议】基本规则与发帖指引 中回复
二、坚决禁止任何违规信息言论,包括(但不限于)政治、喵、喵、喵、喵、宗教、种族的内容(包括内容和标题擦边或含有不良链接的内容)。
?????????
2018-08-20T10:07:18 点赞:0
在 【建议】画板功能吐槽(注:非常合理) 中回复
出一个颜色:透明色,RGB是(0, 0, 0, 0)!这样就可以配合染色工具把背景改成透明色,就可以P图了。
2018-12-16T11:05:28 点赞:0
在 【Python福利】告诉我你最想要的Python书,我送你!(活动已结束) 中回复
《教孩子学编程》[美]Bryson Payne著
零基础,还挺容易懂的,是我学编程的第一本书,里面有许多超有想象力的范例程序(如乒乓计算器,计算你有多少个乒乓球高、重),彩印,学起来很轻松(但是我已经有了,运营喵就不用帮我买单了)
《Python和Pygame游戏开发指南》[美]Al Sweigart著
中级编程图书,我的第二本编程书,里面有许多游戏的作者的翻版,使用Pygame,比较难,适合“萌佬”。(我也已经有了,运营喵你就省点钱吧)
2019-01-19T14:40:10 点赞:0
在 谁会做Python贪吃蛇游戏。 中回复
import pygame, random
from pygame.locals import *
pygame.init()
UNITSIZE = 50
WINWUNITS = 8
WINHUNITS = 8
WINW = UNITSIZE * WINWUNITS
WINH = UNITSIZE * WINHUNITS
FPS = 2
CLOCK = pygame.time.Clock()
snake = [(3, 3), (2, 3) , (1, 3)]
direction = "right"
score = 0
BGCOLOR = GOLD = (216, 234, 196)
HEADC = BLUE = ( 0, 0, 255)
SNAKEC = RED = (255, 0, 0)
STARC = YELLOW = (255, 255, 0)
SCREEN = pygame.display.set_mode((WINW, WINH))
pygame.display.set_caption("贪吃的小蛇 - 得分:0")
def updateStar():
global star
validPos = []
for x in range(WINWUNITS):
for y in range(WINHUNITS):
validPos.append((x, y))
for invalid in snake:
validPos.remove(invalid)
star = random.choice(validPos)
def unit2rect(units):
return pygame.Rect(units[0] * UNITSIZE, units[1] * UNITSIZE, UNITSIZE, UNITSIZE)
def drawSnake(screen, headc, bodyc, poseslist, radius):
for pos in snake:
if pos == snake[0]:
color = headc
else:
color = bodyc
unitr = unit2rect(pos)
pygame.draw.circle(screen, color, unitr.center, radius)
def drawStar(screen, color, rect):
l = rect.left
w = rect.width
t = rect.top
h = rect.height
pygame.draw.polygon(screen, color, ((l + 0.5 * w, t ),
(l + 0.6 * w, t + 0.4 * h),
(l + w, t + 0.4 * h),
(l + 0.7 * w, t + 0.6 * h),
(l + 0.8 * w, t + h),
(l + 0.5 * w, t + 0.8 * h),
(l + 0.2 * w, t + h),
(l + 0.3 * w, t + 0.6 * h),
(l , t + 0.4 * h),
(l + 0.4 * w, t + 0.4 * h)))
updateStar()
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
elif event.type == KEYDOWN:
if event.key == K_LEFT and direction != "right":
direction = "left"
elif event.key == K_RIGHT and direction != "left":
direction = "right"
elif event.key == K_UP and direction != "down":
direction = "up"
elif event.key == K_DOWN and direction != "up":
direction = "down"
SCREEN.fill(BGCOLOR)
if direction == "left":
snake.insert(0, ((snake[0][0]-1) % WINWUNITS, snake[0][1]))
elif direction == "right":
snake.insert(0, ((snake[0][0]+1) % WINWUNITS, snake[0][1]))
elif direction == "up":
snake.insert(0, (snake[0][0], (snake[0][1]-1) % WINHUNITS))
elif direction == "down":
snake.insert(0, (snake[0][0], (snake[0][1]+1) % WINHUNITS))
drawSnake(SCREEN, HEADC, SNAKEC, snake, UNITSIZE//2)
drawStar(SCREEN, STARC, pygame.Rect(unit2rect(star)))
if snake[0] == star:
score += 1
updateStar()
pygame.display.set_caption("贪吃的小蛇 - 得分:" + str(score))
elif snake[0] in snake[1:]:
pygame.display.update()
pygame.time.wait(3000)
pygame.quit()
exit()
else:
snake.pop()
pygame.display.update()
CLOCK.tick(FPS)2019-01-20T22:10:10 点赞:1
在 谁能告诉我用海龟编辑器编的游戏的一些基本代码的意思 中回复
*1* 去 https://python.codemao.cn/ ,点击右边“下载客户端”下载一个海龟编辑器!用网页版不是长久之选!
*2* 把你想要理解的代码复制并粘贴进来,点击右上角“积木模式”,就可以把代码变成容易理解的积木哦!
*3* 可以去看源码图鉴哟,打开海龟编辑器,点击设置,选择帮助,就可以看到每块积木的详细说明了!
2019-01-25T18:47:27 点赞:1