sun857625879
发表于 2022-3-20 13:48:17
谢谢
n200107
发表于 2022-3-20 20:28:05
看看
Young_CH
发表于 2022-3-20 23:18:51
学习
沐雨尘枫
发表于 2022-4-22 16:51:00
作者大大能不能像不二如是一样做成exe可执行文件附件上来你怎样让我难堪
hejunlong
发表于 2022-5-12 11:22:12
看一看
lotutuve
发表于 2022-6-9 15:58:02
{:5_106:}
tt96tt
发表于 2022-6-10 16:28:16
受教了
大橙子.
发表于 2022-6-13 16:53:12
哇哦
bigliu
发表于 2022-6-27 18:04:13
在小甲鱼的视频看到扒完处理数据卡住了来看看
makliu
发表于 2022-6-28 15:45:29
1111
woritengxu
发表于 2022-11-3 22:45:47
淘宝商品信息爬虫
asdechr
发表于 2022-11-4 09:31:21
import pygame
import random
from pygame.locals import *
pygame.init()
font = pygame.font.Font(None, 20)
screen = pygame.display.set_mode((160, 160))
screen.fill((0, 0, 0, 0))
class Block():
def __init__(self, x, y):
self.value = 0
self.x = x*40
self.y = y*40
def set_value(self, value):
self.value = value
block = pygame.surface.Surface((40, 40))
block.fill((0, 0, 0))
pygame.draw.rect(block, (0, 255, 0), (1, 1, 38, 38), 1)
if self.value:
text = font.render(str(value), True, (0, 255, 0))
block.blit(text, (20-text.get_width()/2, 20-text.get_height()/2))
self.block = block.copy()
def draw(self):
screen.blit(self.block, (self.x, self.y))
blocks = []
for y in range(4):
temp = []
for x in range(4):
block = Block(x, y)
block.set_value(0)
temp.append(block)
blocks.append(temp)
for block in random.sample( for i in range(4) for j in range(4)], 2):
block.set_value(2)
for row in blocks:
for block in row:
block.draw()
pygame.display.flip()
direction = 0 #0 for stop;1 for right;2 for down;3 for left; 4 for up
def get_sequence(index, direction):
if direction % 2 == 1:
temp = .value for j in range(4)]
else:
temp = .value for i in range(4)]
return temp if direction > 2 else list(reversed(temp))
def set_sequence(index, direction, sequence):
if direction % 2 == 1:
path = [(index, j) for j in range(4)]
else:
path = [(i, index) for i in range(4)]
if direction <= 2:
path.reverse()
for p in range(4):
blocks]].set_value(sequence)
def move(sequence):
sequence = list(filter(lambda x:x, sequence))
n = len(sequence)
sequence += *(4-n)
i = 0
res = []
while i < n:
if i < 3 and sequence == sequence:
res.append(sequence*2)
i += 2
else:
res.append(sequence)
i += 1
res += *(4-len(res))
return res
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
if event.type == KEYDOWN:
if event.key == K_RIGHT:
direction = 1
elif event.key == K_DOWN:
direction = 2
elif event.key == K_LEFT:
direction = 3
elif event.key == K_UP:
direction = 4
if direction:
for index in range(4):
sequence = get_sequence(index, direction)
sequence = move(sequence)
set_sequence(index, direction, sequence)
if 2048 in .value for i in range(4) for j in range(4)]:
end = font.render('GAME OVER: YOU WIN!', True, (0, 255, 0))
screen.fill((0, 0, 0))
screen.blit(end, (80-end.get_width()/2, 80-end.get_height()/2))
pygame.display.flip()
while True:
for event in pygame.event.wait():
if event.type == QUIT:
exit()
temp = list(filter(lambda x:not x.value, for i in range(4) for j in range(4)]))
if temp:
block = random.choice(temp)
block.set_value(random.choices(, weights=))
else:
over = font.render('GAME OVER: YOU LOSE!', True, (0, 255, 0))
leave = font.render(' to try again', True, (0, 255, 0))
screen.fill((0, 0, 0))
screen.blit(over, (80-over.get_width()/2, 70-over.get_height()/2))
screen.blit(leave, (80-leave.get_width()/2, 110-leave.get_height()/2))
pygame.display.flip()
while True:
on = False
for event in pygame.event.get():
if event.type == QUIT:
exit()
if event.type == KEYDOWN:
if event.key == K_RETURN:
blocks = []
for y in range(4):
temp = []
for x in range(4):
block = Block(x, y)
block.set_value(0)
temp.append(block)
blocks.append(temp)
for block in random.sample( for i in range(4) for j in range(4)], 2):
block.set_value(2)
on = True
if on:
break
screen.fill((0, 0, 0))
for row in blocks:
for block in row:
block.draw()
pygame.display.flip()
direction = 0
j99d99
发表于 2022-11-7 17:07:47
{:5_106:}
wumin198812
发表于 2022-11-7 21:35:23
kankan11111111
jixiang.hu
发表于 2022-11-8 18:12:08
1111
xiedalu
发表于 2022-11-11 11:24:55
厉害
炖甲鱼汤
发表于 2022-11-11 11:34:04
瞅瞅
futui
发表于 2022-11-11 13:23:13
学以致用啊
tiangtian
发表于 2022-11-11 14:33:20
学习了
Mefine
发表于 2022-11-11 14:44:30
攒攒