У меня есть сетка 10x10, в настоящее время заполненная нулями и выведенная на экран с помощью модуля freetype в Pygame.
Как бы я отображал содержимое списка в цикле for вместо жесткого кодирования строки '0'?
import pygame
import pygame.freetype
# Define some colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
# Create a 2 dimensional array. A two dimensional
# array is simply a list of lists.
grid = [[0 for x in range(10)] for y in range(10)]
# Initialize pygame
pygame.init()
# Set the HEIGHT and WIDTH of the screen
WINDOW_SIZE = [255, 255]
screen = pygame.display.set_mode(WINDOW_SIZE)
# Loop until the user clicks the close button.
done = False
# -------- Main Program Loop -----------
while not done:
# Set the screen background
screen.fill(BLACK)
# Draw the grid
for row in range(10):
for column in range(10):
pygame.freetype.Font(None, 32).render_to(screen, (column * 32, row * 32), '0', WHITE)
pygame.display.flip()
pygame.quit()