2024-03-10 02:46:14 +01:00
|
|
|
import pygame
|
|
|
|
from constant import size, rows, cols
|
2024-03-24 19:28:14 +01:00
|
|
|
import random
|
2024-03-10 02:46:14 +01:00
|
|
|
|
|
|
|
class Board:
|
|
|
|
def __init__(self):
|
|
|
|
self.board = []
|
2024-05-18 22:51:09 +02:00
|
|
|
self.vegetables = []
|
|
|
|
self.soil_features = None
|
2024-03-24 19:28:14 +01:00
|
|
|
self.load_images()
|
|
|
|
self.generate_board()
|
2024-05-26 05:12:46 +02:00
|
|
|
self.vegetable_names = []
|
2024-03-10 02:46:14 +01:00
|
|
|
|
|
|
|
def load_images(self):
|
2024-03-24 19:28:14 +01:00
|
|
|
self.grass = pygame.image.load("board/grass.png")
|
|
|
|
self.dirt = pygame.image.load("board/dirt.png")
|
2024-05-18 17:10:56 +02:00
|
|
|
self.rock = pygame.image.load("board/rock.png")
|
|
|
|
self.weeds = pygame.image.load("board/weeds.png")
|
2024-03-24 20:54:05 +01:00
|
|
|
self.soil = pygame.image.load("board/zyzna.png")
|
2024-03-24 19:28:14 +01:00
|
|
|
|
2024-05-18 22:51:09 +02:00
|
|
|
self.warzywa_images = {
|
2024-05-26 05:12:46 +02:00
|
|
|
"pomidor": [pygame.image.load(f"warzywa/tomato/{i}.jpg") for i in range(1, 10)],
|
|
|
|
"fasola": [pygame.image.load(f"warzywa/Bean/{i}.jpg") for i in range(1, 10)],
|
|
|
|
"dynia": [pygame.image.load(f"warzywa/Pumpkin/{i}.jpg") for i in range(1, 10)],
|
|
|
|
"marchewka": [pygame.image.load(f"warzywa/Carrot/{i}.jpg") for i in range(1, 10)],
|
|
|
|
"ziemniak": [pygame.image.load(f"warzywa/Potato/{i}.jpg") for i in range(1, 10)],
|
|
|
|
"rzodkiewka": [pygame.image.load(f"warzywa/Radish/{i}.jpg") for i in range(1, 10)],
|
|
|
|
"ogorek": [pygame.image.load(f"warzywa/Cucumber/{i}.jpg") for i in range(1, 10)],
|
|
|
|
"kalafior": [pygame.image.load(f"warzywa/Cauliflower/{i}.jpg") for i in range(1, 10)],
|
|
|
|
"kapusta": [pygame.image.load(f"warzywa/Cabbage/{i}.jpg") for i in range(1, 10)],
|
|
|
|
"brokul": [pygame.image.load(f"warzywa/Broccoli/{i}.jpg") for i in range(1, 10)]
|
2024-05-18 22:51:09 +02:00
|
|
|
}
|
|
|
|
self.vegetable_types = {
|
|
|
|
"marchewka": 1,
|
|
|
|
"ziemniak": 2,
|
|
|
|
"pomidor": 3,
|
2024-05-23 23:40:01 +02:00
|
|
|
"fasola": 4,
|
|
|
|
"dynia": 5,
|
|
|
|
"rzodkiewka": 6,
|
|
|
|
"ogorek": 7,
|
|
|
|
"kalafior": 8,
|
|
|
|
"kapusta": 9,
|
|
|
|
"brokul": 10
|
2024-05-18 22:51:09 +02:00
|
|
|
}
|
|
|
|
|
2024-03-24 19:28:14 +01:00
|
|
|
def generate_board(self):
|
2024-05-27 14:59:44 +02:00
|
|
|
self.board = [[random.choice([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) for _ in range(cols)] for _ in range(rows)]
|
2024-05-18 22:51:09 +02:00
|
|
|
self.vegetables = [
|
2024-05-26 05:12:46 +02:00
|
|
|
[None for _ in range(cols)] for _ in range(rows)
|
2024-05-18 22:51:09 +02:00
|
|
|
]
|
2024-05-26 05:12:46 +02:00
|
|
|
self.vegetable_names = [
|
|
|
|
[None for _ in range(cols)] for _ in range(rows)
|
|
|
|
]
|
|
|
|
for row in range(rows):
|
|
|
|
for col in range(cols):
|
2024-05-27 14:59:44 +02:00
|
|
|
if self.board[row][col] in (6, 7, 8, 9):
|
2024-05-26 05:12:46 +02:00
|
|
|
vegetable_type = random.choice(list(self.warzywa_images.keys()))
|
|
|
|
vegetable_image = random.choice(self.warzywa_images[vegetable_type])
|
|
|
|
self.vegetables[row][col] = vegetable_image
|
|
|
|
self.vegetable_names[row][col] = vegetable_type
|
2024-05-18 22:51:09 +02:00
|
|
|
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)
|
|
|
|
}
|
2024-03-10 02:46:14 +01:00
|
|
|
|
|
|
|
def draw_cubes(self, win):
|
|
|
|
for row in range(rows):
|
|
|
|
for col in range(cols):
|
2024-05-18 17:10:56 +02:00
|
|
|
cube_rect = pygame.Rect(col * size, row * size, size, size)
|
|
|
|
cube = self.board[row][col]
|
|
|
|
if row == 4 and col == 4:
|
2024-03-10 02:46:14 +01:00
|
|
|
win.blit(self.grass, cube_rect)
|
2024-03-24 19:28:14 +01:00
|
|
|
elif cube == 0:
|
|
|
|
rock_scale = pygame.transform.scale(self.rock, (size, size))
|
2024-03-10 02:46:14 +01:00
|
|
|
win.blit(self.dirt, cube_rect)
|
2024-05-18 17:10:56 +02:00
|
|
|
win.blit(rock_scale, cube_rect)
|
2024-03-24 19:28:14 +01:00
|
|
|
elif cube == 1:
|
2024-05-18 17:10:56 +02:00
|
|
|
weed_scale = pygame.transform.scale(self.weeds, (size, size))
|
2024-03-24 19:28:14 +01:00
|
|
|
win.blit(self.grass, cube_rect)
|
|
|
|
win.blit(weed_scale, cube_rect)
|
2024-05-18 17:10:56 +02:00
|
|
|
elif cube in (2, 3, 4, 5):
|
|
|
|
win.blit(self.grass, cube_rect)
|
2024-03-24 20:54:05 +01:00
|
|
|
elif cube == 10:
|
|
|
|
win.blit(self.soil, cube_rect)
|
2024-05-18 22:51:09 +02:00
|
|
|
if self.vegetables[row][col]:
|
2024-05-26 05:12:46 +02:00
|
|
|
vegetable_image = pygame.transform.scale(self.vegetables[row][col], (size, size))
|
2024-05-18 22:51:09 +02:00
|
|
|
win.blit(vegetable_image, cube_rect)
|
|
|
|
elif cube == 11:
|
|
|
|
win.blit(self.dirt, cube_rect)
|
|
|
|
if self.vegetables[row][col]:
|
2024-05-26 05:12:46 +02:00
|
|
|
vegetable_image = pygame.transform.scale(self.vegetables[row][col], (size, size))
|
2024-05-18 22:51:09 +02:00
|
|
|
win.blit(vegetable_image, cube_rect)
|
2024-03-24 19:28:14 +01:00
|
|
|
else:
|
2024-05-18 17:10:56 +02:00
|
|
|
win.blit(self.dirt, cube_rect)
|
2024-05-18 22:51:09 +02:00
|
|
|
if self.vegetables[row][col]:
|
2024-05-26 05:12:46 +02:00
|
|
|
vegetable_image = pygame.transform.scale(self.vegetables[row][col], (size, size))
|
2024-05-18 22:51:09 +02:00
|
|
|
win.blit(vegetable_image, cube_rect)
|
2024-03-10 02:46:14 +01:00
|
|
|
|
2024-03-24 19:49:08 +01:00
|
|
|
def is_rock(self, row, col):
|
|
|
|
return self.board[row][col] == 0
|
|
|
|
|
2024-05-18 17:10:56 +02:00
|
|
|
def is_weed(self, row, col):
|
2024-03-24 19:49:08 +01:00
|
|
|
return self.board[row][col] == 1
|
|
|
|
|
2024-05-18 17:10:56 +02:00
|
|
|
def set_grass(self, row, col):
|
|
|
|
self.board[row][col] = 2
|
2024-03-24 20:54:05 +01:00
|
|
|
|
2024-05-18 17:10:56 +02:00
|
|
|
def is_dirt(self, row, col):
|
|
|
|
return self.board[row][col] in (6, 7, 8, 9)
|
2024-03-24 20:54:05 +01:00
|
|
|
|
|
|
|
def set_soil(self, row, col):
|
2024-05-18 17:10:56 +02:00
|
|
|
self.board[row][col] = 10
|
2024-05-18 22:51:09 +02:00
|
|
|
self.vegetables[row][col] = self.vegetables[row][col]
|
2024-05-26 05:12:46 +02:00
|
|
|
|
|
|
|
def set_fakedirt(self, row, col):
|
2024-06-06 23:15:26 +02:00
|
|
|
self.board[row][col] = 11
|
|
|
|
|