Traktor/app/board.py

33 lines
946 B
Python
Raw Normal View History

2021-03-16 10:06:56 +01:00
#!/usr/bin/python3
import random
import pygame
from config import *
class Board:
def __init__(self):
self.__fields = []
self.generate_board()
self.fill()
# print(self.__fields)
def generate_board(self):
for i in range(HORIZONTAL_NUM_OF_FIELDS):
self.__fields.append([])
for j in range(VERTICAL_NUM_OF_FIELDS):
self.__fields[i].append(None)
def fill(self):
colors = [C_RED, C_GREEN, C_BLUE]
for i in range(len(self.__fields)):
for j in range(len(self.__fields[i])):
self.__fields[i][j] = random.choice(colors)
def draw(self, screen: pygame.Surface):
for i in range(len(self.__fields)):
for j in range(len(self.__fields[i])):
rect = pygame.Rect(FIELD_SIZE*i, FIELD_SIZE*j, FIELD_SIZE, FIELD_SIZE)
pygame.draw.rect(screen, self.__fields[i][j], rect)