Zaktualizuj 'plant.py'

This commit is contained in:
Cezary Adamczak 2021-06-21 14:13:44 +02:00
parent e77b8d03f9
commit e9c11d37d2

110
plant.py
View File

@ -1,29 +1,32 @@
import os
import random
from AI.decision_tree import * from AI.decision_tree import *
from src.dimensions import * from src.dimensions import *
from src.sprites import * from src.sprites import *
from src.colors import *
path = os.path.dirname(__file__) + "\\src\\test\\"
class Plant(pygame.sprite.Sprite): class Plant(pygame.sprite.Sprite):
def __init__(self, field, species): def __init__(self, field, species):
super(Plant, self).__init__()
self.species = species self.species = species
if self.species == "wheat": if self.species == "tomato":
self.growth_speed = 1.5
self.humidity_needed = 2
self.img0 = wheat_img_0 self.img0 = wheat_img_0
self.img1 = wheat_img_1 self.img1 = wheat_img_1
self.img2 = wheat_img_2 self.img2 = wheat_img_2
self.img3 = wheat_img_3 self.img3 = wheat_img_3
elif self.species == "potato": elif self.species == "potato":
self.growth_speed = 1
self.humidity_needed = 1
self.img0 = potato_img_0 self.img0 = potato_img_0
self.img1 = potato_img_1 self.img1 = potato_img_1
self.img2 = potato_img_2 self.img2 = potato_img_2
self.img3 = potato_img_3 self.img3 = potato_img_3
elif self.species == "strawberry": elif self.species == "strawberry":
self.growth_speed = 0.8 self.img0 = strawberry_img_0
self.humidity_needed = 1 self.img1 = strawberry_img_1
self.img2 = strawberry_img_2
self.img3 = strawberry_img_3
elif self.species == "pepper":
self.img0 = strawberry_img_0 self.img0 = strawberry_img_0
self.img1 = strawberry_img_1 self.img1 = strawberry_img_1
self.img2 = strawberry_img_2 self.img2 = strawberry_img_2
@ -38,9 +41,94 @@ class Plant(pygame.sprite.Sprite):
field.planted = True field.planted = True
self.tickscount = 0 self.tickscount = 0
self.ticks = 0 self.ticks = 0
self.path = path + self.species + "\\"
self.testimage = self.path + random.choice(os.listdir(self.path))
def dtree(self): def dtree(self):
decision_tree(self) if self.field.hydration == 4:
if self.is_healthy == 1:
if self.field.tractor_there == 0:
if self.ticks == 0:
return 0
elif self.ticks == 1:
return 1
elif self.field.tractor_there == 1:
return 0
elif self.is_healthy == 0:
return 0
elif self.field.hydration == 2:
if self.species == "pepper":
if self.ticks == 1:
if self.is_healthy == 1:
return 1
elif self.is_healthy == 0:
return 0
elif self.ticks == 0:
return 0
elif self.species == "potato":
return 0
elif self.species == "tomato":
return 0
elif self.species == "strawberry":
return 0
elif self.field.hydration == 1:
if self.species == "potato":
return 0
elif self.species == "strawberry":
if self.ticks == 1:
return -1
elif self.ticks == 0:
return 0
elif self.species == "tomato":
return 0
elif self.species == "pepper":
if self.is_healthy == 0:
return 0
elif self.is_healthy == 1:
if self.field.tractor_there == 0:
if self.ticks == 0:
return 0
elif self.ticks == 1:
return 1
elif self.field.tractor_there == 1:
return 0
elif self.field.hydration == 3:
if self.ticks == 1:
if self.field.tractor_there == 0:
if self.is_healthy == 1:
if self.species == "potato":
if self.field.fertility == 1:
return 1
elif self.field.fertility == 0:
return 0
elif self.species == "strawberry":
return 1
elif self.species == "pepper":
return 1
elif self.species == "tomato":
return 1
elif self.is_healthy == 0:
return 0
elif self.field.tractor_there == 1:
return 0
elif self.ticks == 0:
return 0
elif self.field.hydration == 5:
if self.field.tractor_there == 1:
return 0
elif self.field.tractor_there == 0:
if self.is_healthy == 0:
return 0
elif self.is_healthy == 1:
if self.ticks == 1:
return 1
elif self.ticks == 0:
return 0
elif self.field.hydration == 0:
if self.ticks == 0:
return 0
elif self.ticks == 1:
return -1
def update(self): def update(self):
if self.growth == 0: if self.growth == 0:
@ -63,6 +151,7 @@ class Plant(pygame.sprite.Sprite):
self.growth = 4 self.growth = 4
if self.growth < 0: if self.growth < 0:
self.growth = 0 self.growth = 0
self.update() self.update()
def tick(self): def tick(self):
@ -70,3 +159,6 @@ class Plant(pygame.sprite.Sprite):
if self.tickscount >= 25: if self.tickscount >= 25:
self.tickscount = 0 self.tickscount = 0
self.ticks = 1 self.ticks = 1
def remove(self):
self.field.planted = False