refactor(tile_init): set type based on random vegetable

This commit is contained in:
Wojciech Kubicki 2024-03-25 01:52:34 +01:00
parent 8ce604df46
commit 7de410c59a

View File

@ -6,22 +6,24 @@ import pytholog as pl
import random import random
class Tile(pygame.sprite.Sprite): class Tile(pygame.sprite.Sprite):
def __init__(self, id, type, field): def __init__(self, id, field, type):
super().__init__() super().__init__()
self.id = id self.id = id
x = id%16 x = id%16
y = id//16 y = id//16
vegetable_types = tractor_kb.query(pl.Expr("warzywo(X)"))
random_vegetable = vegetable_types[random.randint(0, len(vegetable_types)-1)]['X']
self.type = type
self.field = field self.field = field
vegetables = tractor_kb.query(pl.Expr("warzywo(Nazwa_warzywa)"))
random_vegetable = vegetables[random.randint(0, len(vegetables)-1)]['Nazwa_warzywa']
self.set_type(random_vegetable) self.set_type(random_vegetable)
self.rect = self.image.get_rect()
self.faza = 'posadzono'
# you can set TILE_SIZE in the .env file to adjust the window size # you can set TILE_SIZE in the .env file to adjust the window size
load_dotenv(find_dotenv()) load_dotenv(find_dotenv())
TILE_SIZE = int(os.getenv("TILE_SIZE")) TILE_SIZE = int(os.getenv("TILE_SIZE"))
self.rect = self.image.get_rect()
self.rect.topleft = (x * TILE_SIZE, y * TILE_SIZE) self.rect.topleft = (x * TILE_SIZE, y * TILE_SIZE)
def draw(self, surface): def draw(self, surface):