Traktor/app/board.py
2021-03-16 12:20:06 +01:00

49 lines
1.5 KiB
Python

#!/usr/bin/python3
import random
from images import *
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(soilType)
def draw(self, screen: pygame.Surface):
for x in range(len(self.__fields)):
for y in range(len(self.__fields[x])):
obj = self.__fields[x][y]
if obj == 'grass':
grassrect.center = (x, y)
screen.blit(grass, grassrect)
if obj == 'corn':
cornrect.center = (x, y)
screen.blit(corn, cornrect)
if obj == 'sunflower':
sunflowerrect.center = (x, y)
screen.blit(sunflower, sunflowerrect)
if obj == 'sand':
sandrect.center = (x, y)
screen.blit(sand, sandrect)
if obj == 'clay':
clayrect.center = (x, y)
screen.blit(clay, clayrect)