import pygame
pygame.init()
level = [
"BB BB",
"BB BB BB BB BB",
"BB BB BB",
"BB BB",
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
]
x = y = 0
BLACK = (0,0,0) #RGB
WHITE = (255,255,255) #RGB
BLOCKSIZE = 16 #width and height of the block
screen = pygame.display.set_mode((len(level[0])*BLOCKSIZE,len(level)*BLOCKSIZE),0,32)
screen.fill(WHITE)
for row in level: #level is your array that you have shown above in your question
for cell in row:
if cell == "B":
screen.fill(BLACK,(x,y,BLOCKSIZE,BLOCKSIZE))
x += BLOCKSIZE
y += BLOCKSIZE
x = 0
pygame.display.update()
while True:
#loop through your code
基本上,您循环遍历列表的每个字符,如果那里有一个块,则在其相应位置绘制一个黑色方块。
此外,您的级别列表应在所有行之后包含逗号(因为它是一个列表)