由于你的代码没有有效信息,也不能运行,我大概猜测了你的意图,修改了一下代码
blocks.pyimport random
from copy import deepcopy
# I型
Ilist = [[(1, 0), (1, 1), (1, 2), (1, 3)], [(0, 2), (1, 2), (2, 2), (3, 2)]]
# O型
Olist = [[(1, 1), (1, 2), (2, 1), (2, 2)]]
# Z型
Zlist = [[(2, 0), (2, 1), (1, 1), (1, 2)], [(0, 1), (1, 1), (1, 2), (2, 2)]]
# S型
Slist = [[(1, 0), (1, 1), (2, 1), (2, 2)], [(0, 2), (1, 2), (1, 1), (2, 1)]]
# L型
Llist = [
[(1, 0), (1, 1), (1, 2), (2, 2)],
[(0, 1), (1, 1), (2, 1), (0, 2)],
[(0, 0), (1, 0), (1, 1), (1, 2)],
[(0, 1), (1, 1), (2, 1), (2, 0)],
]
# J型
Jlist = [
[(1, 0), (1, 1), (1, 2), (0, 2)],
[(0, 1), (1, 1), (2, 1), (0, 0)],
[(2, 0), (1, 0), (1, 1), (1, 2)],
[(0, 1), (1, 1), (2, 1), (2, 2)],
]
# T型
Tlist = [
[(0, 1), (1, 1), (2, 1), (1, 2)],
[(1, 0), (1, 1), (1, 2), (0, 1)],
[(0, 1), (1, 1), (2, 1), (1, 0)],
[(1, 0), (1, 1), (1, 2), (2, 1)],
]
class Block:
shapeList = [Ilist, Olist, Zlist, Slist, Llist, Jlist, Tlist]
def __init__(self):
self.randomShape()
def randomShape(self):
self.rectList = deepcopy(random.choice(self.shapeList))
main.pyimport pygame
from blocks import *
class MainScreen(Block):
def __init__(self):
super().__init__()
self.screen = pygame.display.set_mode((1920,1080))
def draw(self):
self.screen.fill((50, 50, 50))
self.randomShape() # 随机选择形状
for row in self.rectList:
for x, y in row:
print(x, y)
ms = MainScreen()
ms.draw()
|