118 lines
4.7 KiB
Python
118 lines
4.7 KiB
Python
import pygame
|
|
from constant import size, rows, cols
|
|
import random
|
|
|
|
class Board:
|
|
def __init__(self):
|
|
self.board = []
|
|
self.vegetables = []
|
|
self.soil_features = None
|
|
self.load_images()
|
|
self.generate_board()
|
|
|
|
def load_images(self):
|
|
self.grass = pygame.image.load("board/grass.png")
|
|
self.dirt = pygame.image.load("board/dirt.png")
|
|
self.rock = pygame.image.load("board/rock.png")
|
|
self.weeds = pygame.image.load("board/weeds.png")
|
|
self.soil = pygame.image.load("board/zyzna.png")
|
|
|
|
self.warzywa_images = {
|
|
"pomidor": pygame.image.load("warzywa/pomidor.png"),
|
|
"salata": pygame.image.load("warzywa/salata.png"),
|
|
"cebula": pygame.image.load("warzywa/cebula.png"),
|
|
"marchewka": pygame.image.load("warzywa/marchewka.png"),
|
|
"ziemniak": pygame.image.load("warzywa/ziemniak.png"),
|
|
"papryka": pygame.image.load("warzywa/papryka.png"),
|
|
"burak": pygame.image.load("warzywa/burak.png"),
|
|
"brukselka": pygame.image.load("warzywa/brukselka.png"),
|
|
"szpinak": pygame.image.load("warzywa/szpinak.png"),
|
|
"rzepak": pygame.image.load("warzywa/rzepak.png")
|
|
}
|
|
self.vegetable_types = {
|
|
"marchewka": 1,
|
|
"ziemniak": 2,
|
|
"pomidor": 3,
|
|
"salata": 4,
|
|
"cebula": 5,
|
|
"papryka": 6,
|
|
"burak": 7,
|
|
"brukselka": 8,
|
|
"szpinak": 9,
|
|
"rzepak": 10
|
|
}
|
|
|
|
def generate_board(self):
|
|
self.board = [[random.choice([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) for _ in range(cols)] for _ in range(rows)]
|
|
self.vegetables = [
|
|
[random.choice(list(self.warzywa_images.keys())) if self.board[row][col] in (6, 7, 8, 9) else None for col in range(cols)]
|
|
for row in range(rows)
|
|
]
|
|
self.soil_features = self.generate_soil_features()
|
|
|
|
|
|
print(f"Shared soil features: {self.soil_features}")
|
|
|
|
def generate_soil_features(self):
|
|
return {
|
|
"wilgotnosc_gleby": random.randint(30, 70),
|
|
"temperatura_gleby": random.randint(13, 26),
|
|
"opady_deszczu": random.randint(0, 11),
|
|
"wiek_rosliny": random.randint(1, 9),
|
|
"proc_ekspo_na_swiatlo": random.randint(10, 90),
|
|
"pora_dnia": random.randint(8, 20),
|
|
"pora_roku": random.randint(1, 4)
|
|
}
|
|
|
|
def draw_cubes(self, win):
|
|
for row in range(rows):
|
|
for col in range(cols):
|
|
cube_rect = pygame.Rect(col * size, row * size, size, size)
|
|
cube = self.board[row][col]
|
|
if row == 4 and col == 4:
|
|
win.blit(self.grass, cube_rect)
|
|
elif cube == 0:
|
|
rock_scale = pygame.transform.scale(self.rock, (size, size))
|
|
win.blit(self.dirt, cube_rect)
|
|
win.blit(rock_scale, cube_rect)
|
|
elif cube == 1:
|
|
weed_scale = pygame.transform.scale(self.weeds, (size, size))
|
|
win.blit(self.grass, cube_rect)
|
|
win.blit(weed_scale, cube_rect)
|
|
elif cube in (2, 3, 4, 5):
|
|
win.blit(self.grass, cube_rect)
|
|
elif cube == 10:
|
|
win.blit(self.soil, cube_rect)
|
|
if self.vegetables[row][col]:
|
|
vegetable_image = pygame.transform.scale(self.warzywa_images[self.vegetables[row][col]], (size, size))
|
|
win.blit(vegetable_image, cube_rect)
|
|
elif cube == 11:
|
|
win.blit(self.dirt, cube_rect)
|
|
if self.vegetables[row][col]:
|
|
vegetable_image = pygame.transform.scale(self.warzywa_images[self.vegetables[row][col]],
|
|
(size, size))
|
|
win.blit(vegetable_image, cube_rect)
|
|
else:
|
|
win.blit(self.dirt, cube_rect)
|
|
if self.vegetables[row][col]:
|
|
vegetable_image = pygame.transform.scale(self.warzywa_images[self.vegetables[row][col]], (size, size))
|
|
win.blit(vegetable_image, cube_rect)
|
|
|
|
def is_rock(self, row, col):
|
|
return self.board[row][col] == 0
|
|
|
|
def is_weed(self, row, col):
|
|
return self.board[row][col] == 1
|
|
|
|
def set_grass(self, row, col):
|
|
self.board[row][col] = 2
|
|
|
|
def is_dirt(self, row, col):
|
|
return self.board[row][col] in (6, 7, 8, 9)
|
|
|
|
def set_soil(self, row, col):
|
|
self.board[row][col] = 10
|
|
self.vegetables[row][col] = self.vegetables[row][col]
|
|
def set_fakedirt(self,row,col):
|
|
self.board[row][col] = 11
|