代码: 全选
def variation_blocks():
def rotate(p):
x,y = p
return -y,x
def normalize(block):
min_x = min(dx for dx,dy in block)
min_y = min(dy for dx,dy in block)
nblock = [(dx-min_x, dy-min_y) for dx,dy in block]
return nblock
def variation_block(block):
nblocks = []
nb = block
for i in range(4):
nb = sorted(nb)
nblocks.append(tuple(nb))
nb = [game.rotate(c) for c in nb]
nb = game.normalize(nb)
nblocks = list(set(nblocks))
return nblocks
game.tetris_blocks = []
for block in game.base_tetris_blocks:
nblocks = game.variation_block(block["shape"])
game.tetris_blocks += [{"shape": b, "color": block["color"]} for b in nblocks]
def set_game_blocks():
game.base_tetris_blocks = [
{"shape": [(0, 0), (0, 1), (0, 2), (0, 3)], "color": "#6DB3AC"}, # I (4-square)
{"shape": [(0, 0), (0, 1), (1, 0), (1, 1)], "color": "#F0F000"}, # O
{"shape": [(0, 0), (1, 0), (1, 1), (2, 0)], "color": "#BD4DF5"}, # T
{"shape": [(0, 1), (0, 2), (1, 0), (1, 1)], "color": "#00F000"}, # S
{"shape": [(0, 0), (0, 1), (1, 1), (1, 2)], "color": "#F00000"}, # Z
{"shape": [(0, 0), (1, 0), (2, 0), (2, 1)], "color": "#699EEB"}, # J
{"shape": [(0, 1), (1, 1), (2, 0), (2, 1)], "color": "#F0A000"}, # L
# Custom blocks
{"shape": [(0, 0)], "color": "#F09050"}, # 1-square
{"shape": [(0, 0), (0, 1)], "color": "#6FEA85"}, # 2-square
{"shape": [(0, 0), (0, 1), (0, 2)], "color": "#B34DB3"}, # 3-line
{"shape": [(0, 0), (0, 1), (1, 1)], "color": "#A5B350"}, # L-3
# 5-square blocks
{"shape": [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4)], "color": "#D0603C"}, # 5-line (Dark Turquoise)
{"shape": [(0, 0), (0, 1), (0, 2), (1, 2), (2, 2)], "color": "#C8BA4A"}, # Right-angle (Red)
# 9-square block
{"shape": [
(0, 0), (0, 1), (0, 2),
(1, 0), (1, 1), (1, 2),
(2, 0), (2, 1), (2, 2)
], "color": "#FFD700"} # 3x3 (Gold)
]
variation_blocks()