2021-03-16 10:06:56 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import random
|
2021-03-16 12:20:06 +01:00
|
|
|
from images import *
|
2021-03-16 10:06:56 +01:00
|
|
|
|
|
|
|
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):
|
2021-03-16 12:20:06 +01:00
|
|
|
# colors = [C_RED, C_GREEN, C_BLUE]
|
2021-03-16 10:06:56 +01:00
|
|
|
for i in range(len(self.__fields)):
|
|
|
|
for j in range(len(self.__fields[i])):
|
2021-03-16 12:20:06 +01:00
|
|
|
self.__fields[i][j] = random.choice(soilType)
|
|
|
|
|
2021-03-16 10:06:56 +01:00
|
|
|
|
|
|
|
def draw(self, screen: pygame.Surface):
|
2021-03-16 12:20:06 +01:00
|
|
|
for x in range(len(self.__fields)):
|
|
|
|
for y in range(len(self.__fields[x])):
|
|
|
|
obj = self.__fields[x][y]
|
2021-03-16 13:47:37 +01:00
|
|
|
pos_x = x * FIELD_SIZE + FIELD_SIZE//2
|
|
|
|
pos_y = y * FIELD_SIZE + FIELD_SIZE//2
|
2021-03-16 12:20:06 +01:00
|
|
|
if obj == 'grass':
|
2021-03-16 13:47:37 +01:00
|
|
|
grassrect.center = (pos_x, pos_y)
|
2021-03-16 12:20:06 +01:00
|
|
|
screen.blit(grass, grassrect)
|
|
|
|
if obj == 'corn':
|
2021-03-16 13:47:37 +01:00
|
|
|
cornrect.center = (pos_x, pos_y)
|
2021-03-16 12:20:06 +01:00
|
|
|
screen.blit(corn, cornrect)
|
|
|
|
if obj == 'sunflower':
|
2021-03-16 13:47:37 +01:00
|
|
|
sunflowerrect.center = (pos_x, pos_y)
|
2021-03-16 12:20:06 +01:00
|
|
|
screen.blit(sunflower, sunflowerrect)
|
|
|
|
if obj == 'sand':
|
2021-03-16 13:47:37 +01:00
|
|
|
sandrect.center = (pos_x, pos_y)
|
2021-03-16 12:20:06 +01:00
|
|
|
screen.blit(sand, sandrect)
|
|
|
|
if obj == 'clay':
|
2021-03-16 13:47:37 +01:00
|
|
|
clayrect.center = (pos_x , pos_y)
|
2021-03-16 12:20:06 +01:00
|
|
|
screen.blit(clay, clayrect)
|
|
|
|
|