From a5691816ace8695b050eb7b4cf490083d23fc77b Mon Sep 17 00:00:00 2001 From: jakzar Date: Sun, 24 Mar 2024 23:30:02 +0100 Subject: [PATCH] -Merged classes slot and roslina. -Added function to display current status of plant. --- App.py | 11 ++++++++++- Image.py | 4 ++-- Pole.py | 8 +++++++- Roslina.py | 16 +++++++++++++++- Slot.py | 9 +++++++-- Stan.py | 14 +++++++++++++- 6 files changed, 54 insertions(+), 8 deletions(-) diff --git a/App.py b/App.py index d22af9b..8029d49 100644 --- a/App.py +++ b/App.py @@ -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 + diff --git a/Image.py b/Image.py index c08f264..4bd8136 100644 --- a/Image.py +++ b/Image.py @@ -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] \ No newline at end of file + return (plant_name,self.plants_image_dict[plant_name]) \ No newline at end of file diff --git a/Pole.py b/Pole.py index 9500ad5..017848e 100644 --- a/Pole.py +++ b/Pole.py @@ -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() \ No newline at end of file diff --git a/Roslina.py b/Roslina.py index 172060f..48f3479 100644 --- a/Roslina.py +++ b/Roslina.py @@ -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ęć @@ -65,4 +76,7 @@ class Roslina: while self.stan.akcja != None: self.doAkcja() self.stan.checkStan() - return \ No newline at end of file + return + + def report_status(self): + return f"Nazwa rosliny: {self.nazwa} "+self.stan.report_all() \ No newline at end of file diff --git a/Slot.py b/Slot.py index ec96a6a..4ca10fa 100644 --- a/Slot.py +++ b/Slot.py @@ -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() \ No newline at end of file diff --git a/Stan.py b/Stan.py index 99cff4e..5789e25 100644 --- a/Stan.py +++ b/Stan.py @@ -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 @@ -33,4 +42,7 @@ class Stan: return else: self.akcja = None - return \ No newline at end of file + return + + def report_all(self): + return f"Nawodnienie: {self.nawodnienie} Zyznosc: {self.zyznosc} Wzrost: {self.wzrost} Choroba: {self.choroba}" \ No newline at end of file