Added fields and methods to classes: plant, field, tractor, crop protection products

This commit is contained in:
JakubStac 2024-03-22 22:14:05 +01:00
parent dc4a34e930
commit 679b8ca1b8
8 changed files with 64 additions and 13 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (Traktor)" project-jdk-type="Python SDK" />
</project>

View File

@ -3,7 +3,7 @@ import pygame
WIDTH, HEIGHT = 1000, 1000
FIELD_WIDTH, FIELD_HEIGHT = 660, 330
ROWS, COLS = 10, 5
ROWS, COLS = 20, 20
# number of tiles in a row and column
TILE_SIZE = FIELD_WIDTH//ROWS
PLANT = ""

View File

@ -21,10 +21,9 @@ def positionFieldElements():
tractor.y += fieldY
def createTiles():
for y in range (0,COLS):
for x in range (0,ROWS):
for y in range(0, COLS):
for x in range(0, ROWS):
tile = Tile(x*TILE_SIZE, y*TILE_SIZE)
tile.randomize_photo()
tile.randomizeContent()
tiles.append(tile)
positionFieldElements()

View File

@ -2,8 +2,23 @@ class Tractor:
x = None
y = None
image = None
# etc
def __init__(self,x,y):
def __init__(self, x, y):
self.x = x
self.y = y
self.image = 'resources/images/tractor.png'
def work_on_field(self, ground, plant):
if plant is None:
pass # zasadz cos
if ground.pest == True:
# traktor pozbywa sie szkodnikow
ground.pest = False
if ground.weed == True:
# traktor pozbywa się chwastow
ground.weed = False
if ground.water < plant.water_requirements:
ground.water += 20
if ground.nutrients < plant.nutrients_requirements:
ground.nutrients += 20

View File

@ -0,0 +1,3 @@
class CropProtectionProduct:
def __init__(self, strong_against):
self.strong_against = strong_against # pestycyd, herbicyd

View File

@ -1,6 +1,26 @@
import random
class Dirt:
state = None
def __init__(self, water_level, nutrients_level):
self.water_level = water_level
self.nutrients_level = nutrients_level
self.pest = False
self.weed = False
self.obstacle = False
self.pests_and_weeds()
# add a couple new properties
# add init, getters,setters
def pests_and_weeds(self):
i = random.randint(1, 20) # 5% szans na szkodniki, 10% na chwasty, 5 na obydwa 15 na kamien
if i == 1:
self.pest = True
elif i == 2 or i == 3:
self.weed = True
elif i == 4:
self.weed = True
self.pest = True
elif i == 5 or i == 6 or i == 7:
self.obstacle = True
# add init, getters,setters

View File

@ -1,8 +1,22 @@
import random
class Plant:
name = None
def __init__(self, name, plant_type, water_requirements, nutrients_requirements, growth_level):
self.name = name
self.plant_type = plant_type
self.water_requirements = water_requirements
self.nutrients_requirements = nutrients_requirements
self.growth_level = growth_level
def try_to_grow(self, water, nutrients):
if (water >= self.water_requirements) and (nutrients >= self.nutrients_requirements):
i = random.randint(5, 12)
if self.growth_level+i > 100:
i = self.growth_level - 100
self.growth_level += i
# more properties
# add init, getters,setters

View File

@ -1,7 +1,7 @@
import random
import os
#path to plant images folder (used in randomize_photo function)
# path to plant images folder (used in randomize_photo function)
folder_path = "resources\images\plant_photos"
@ -26,7 +26,7 @@ class Tile:
# called on a created tile
#choose random photo from the folder:
# choose random photo from the folder:
def randomize_photo(self):
random_photo = random.choice(os.listdir(folder_path))
@ -39,7 +39,7 @@ class Tile:
if i == 1:
self.image = "resources/images/sampling.png"
self.photo = photo_path
#self.photo losuje dodatkowo zdjecie jakies rosliny do danego rzędu
# self.photo losuje dodatkowo zdjecie jakies rosliny do danego rzędu
else:
self.image = "resources/images/dirt.png"
self.photo = "resources/images/background.jpg"