Traktor/app/board.py

57 lines
1.8 KiB
Python
Raw Normal View History

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 13:27:39 +01:00
size = (FIELD_SIZE/HORIZONTAL_NUM_OF_FIELDS, FIELD_SIZE/HORIZONTAL_NUM_OF_FIELDS)
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:27:39 +01:00
i = x * FIELD_SIZE
j = y * FIELD_SIZE
2021-03-16 12:20:06 +01:00
if obj == 'grass':
2021-03-16 13:27:39 +01:00
grassrect.size = (size)
grassrect.center = (i, j)
2021-03-16 12:20:06 +01:00
screen.blit(grass, grassrect)
if obj == 'corn':
2021-03-16 13:27:39 +01:00
cornrect.size = (size)
cornrect.center = (i, j)
2021-03-16 12:20:06 +01:00
screen.blit(corn, cornrect)
if obj == 'sunflower':
2021-03-16 13:27:39 +01:00
sunflowerrect.size = (size)
sunflowerrect.center = (i, j)
2021-03-16 12:20:06 +01:00
screen.blit(sunflower, sunflowerrect)
if obj == 'sand':
2021-03-16 13:27:39 +01:00
sandrect.size = (size)
sandrect.center = (i, j)
2021-03-16 12:20:06 +01:00
screen.blit(sand, sandrect)
if obj == 'clay':
2021-03-16 13:27:39 +01:00
clayrect.size = (size)
clayrect.center = (i, j)
2021-03-16 12:20:06 +01:00
screen.blit(clay, clayrect)