-Merged classes slot and roslina. -Added function to display current status of plant.

This commit is contained in:
jakzar 2024-03-24 23:30:02 +01:00
parent 4c9bbed441
commit a5691816ac
6 changed files with 54 additions and 8 deletions

11
App.py
View File

@ -20,7 +20,9 @@ pole.draw_grid() #musi byc tutaj wywołane ponieważ inicjalizuje sloty do slown
traktor_slot = pole.get_slot_from_cord((0, 0))
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.plug)
def init_demo(): #Demo purpose
old_info=""
traktor.draw_tractor()
time.sleep(2)
pole.randomize_colors()
@ -28,11 +30,11 @@ def init_demo(): #Demo purpose
while True:
time.sleep(0.5)
demo_move()
old_info=get_info(old_info)
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
def init(demo):
pygame.display.update()
if(demo==True):
@ -46,5 +48,12 @@ def demo_move():
current_slot.redraw_image() # Przerysowanie obrazu dla aktualnego slotu
traktor.random_move(pole)
def get_info(old_info):
(x,y)=pygame.mouse.get_pos()
new_info=pole.check_collision(x,y)
if(old_info!=new_info):
print(new_info)
return new_info

View File

@ -23,7 +23,7 @@ class Image:
x=random.randint(0,5)
keys=list(self.plants_image_dict.keys())
plant=keys[x]
return self.plants_image_dict[plant]
return (plant,self.plants_image_dict[plant])
def return_plant(self,plant_name):
return self.plants_image_dict[plant_name]
return (plant_name,self.plants_image_dict[plant_name])

View File

@ -4,7 +4,7 @@ import Colors
import pygame
import time
import Ui
import math
class Pole:
def __init__(self,screen,image_loader):
@ -51,3 +51,9 @@ class Pole:
def is_valid_move(self, coordinates):
return coordinates in self.slot_dict
def check_collision(self,mouse_x,mouse_y):
mouse_x=math.floor(mouse_x/dCon.CUBE_SIZE)
mouse_y=math.floor(mouse_y/dCon.CUBE_SIZE)
collided=self.get_slot_from_cord((mouse_x,mouse_y))
return collided.print_status()

View File

@ -1,3 +1,7 @@
import Stan
import Srodek
import random
class Roslina:
nazwa = None #[string]
stan = None #[Stan]
@ -36,6 +40,13 @@ class Roslina:
self.stan = stan
self.srodek = srodek
def __init__(self,nazwa):
self.nazwa=nazwa
self.stan=Stan.Stan()
self.stan.set_random()
self.srodek=None
def checkSrodek(self):
#może wykorzystać AI do porównywania zdjęć
@ -66,3 +77,6 @@ class Roslina:
self.doAkcja()
self.stan.checkStan()
return
def report_status(self):
return f"Nazwa rosliny: {self.nazwa} "+self.stan.report_all()

View File

@ -3,6 +3,7 @@ import displayControler as dCon
import Colors
import random
import Image
import Roslina
BORDER_THICKNESS=1 #Has to be INT value
class Slot:
@ -10,7 +11,7 @@ class Slot:
self.x_axis=x_axis
self.y_axis=y_axis
self.plant_image = None
self.plant=color #TODO CHANGE IT BY HOOKING PLANT CLASS
self.plant=None
self.screen=screen
self.field=pygame.Rect(self.x_axis*dCon.CUBE_SIZE,self.y_axis*dCon.CUBE_SIZE,dCon.CUBE_SIZE,dCon.CUBE_SIZE)
self.image_loader=image_loader
@ -28,7 +29,8 @@ class Slot:
self.draw()
def set_random_plant(self):
self.plant=self.random_plant()
(plant_name,self.plant_image)=self.random_plant()
self.plant=Roslina.Roslina(plant_name)
self.set_image()
def set_image(self):
@ -40,3 +42,6 @@ class Slot:
def random_plant(self): #Probably will not be used later only for demo purpouse
return self.image_loader.return_random_plant()
def print_status(self):
return f"wspolrzedne: (X:{self.x_axis} Y:{self.y_axis}) "+self.plant.report_status()

12
Stan.py
View File

@ -1,4 +1,5 @@
import Akcja
import random
class Stan:
nawodnienie = None #[int] 0-100 (0-60: trzeba podlać), spada w zaleznosci od rosliny: aktualizowane bedzie "w tle"
@ -15,6 +16,14 @@ class Stan:
self.wzrost = wzrost
self.choroba = choroba
def __init__(self):
self.nawodnienie=0
def set_random(self):
self.nawodnienie=random.randint(0,100)
self.zyznosc=random.randint(0,100)
self.wzrost=random.randint(0,100)
self.choroba=random.choice(["brak","grzyb","bakteria","pasozyt"])
def checkStan(self):
# sprawdza stan rośliny i podejmuje akcje jeśli potrzebna
@ -34,3 +43,6 @@ class Stan:
else:
self.akcja = None
return
def report_all(self):
return f"Nawodnienie: {self.nawodnienie} Zyznosc: {self.zyznosc} Wzrost: {self.wzrost} Choroba: {self.choroba}"