From 8ce604df467cf30dd338b2785fc807e1a0bbf7fa Mon Sep 17 00:00:00 2001 From: Wojciech Kubicki Date: Mon, 25 Mar 2024 01:27:20 +0100 Subject: [PATCH] feat(tile_type): randomly assign each tile a vegetable at init --- src/tile.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/tile.py b/src/tile.py index b4b9e577..94f78652 100644 --- a/src/tile.py +++ b/src/tile.py @@ -1,6 +1,9 @@ import os import pygame from dotenv import find_dotenv, load_dotenv +from kb import tractor_kb +import pytholog as pl +import random class Tile(pygame.sprite.Sprite): def __init__(self, id, type, field): @@ -8,9 +11,13 @@ class Tile(pygame.sprite.Sprite): self.id = id x = 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.set_type(type) + self.set_type(random_vegetable) self.rect = self.image.get_rect() # you can set TILE_SIZE in the .env file to adjust the window size load_dotenv(find_dotenv()) @@ -22,8 +29,10 @@ class Tile(pygame.sprite.Sprite): def set_type(self, type): self.type = type - if self.type == 'grass': - self.image = pygame.image.load("images/grass.png").convert() + # if self.type == 'grass': + # self.image = pygame.image.load("images/grass.png").convert() + self.image = pygame.image.load("images/grass.png").convert() + # you can set TILE_SIZE in the .env file to adjust the window size load_dotenv(find_dotenv()) TILE_SIZE = int(os.getenv("TILE_SIZE"))