-Merged classes slot and roslina. -Added function to display current status of plant.
This commit is contained in:
parent
4c9bbed441
commit
a5691816ac
11
App.py
11
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_slot = pole.get_slot_from_cord((0, 0))
|
||||||
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.plug)
|
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.plug)
|
||||||
|
|
||||||
|
|
||||||
def init_demo(): #Demo purpose
|
def init_demo(): #Demo purpose
|
||||||
|
old_info=""
|
||||||
traktor.draw_tractor()
|
traktor.draw_tractor()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
pole.randomize_colors()
|
pole.randomize_colors()
|
||||||
@ -28,11 +30,11 @@ def init_demo(): #Demo purpose
|
|||||||
while True:
|
while True:
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
demo_move()
|
demo_move()
|
||||||
|
old_info=get_info(old_info)
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
|
|
||||||
def init(demo):
|
def init(demo):
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
if(demo==True):
|
if(demo==True):
|
||||||
@ -46,5 +48,12 @@ def demo_move():
|
|||||||
current_slot.redraw_image() # Przerysowanie obrazu dla aktualnego slotu
|
current_slot.redraw_image() # Przerysowanie obrazu dla aktualnego slotu
|
||||||
traktor.random_move(pole)
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
4
Image.py
4
Image.py
@ -23,7 +23,7 @@ class Image:
|
|||||||
x=random.randint(0,5)
|
x=random.randint(0,5)
|
||||||
keys=list(self.plants_image_dict.keys())
|
keys=list(self.plants_image_dict.keys())
|
||||||
plant=keys[x]
|
plant=keys[x]
|
||||||
return self.plants_image_dict[plant]
|
return (plant,self.plants_image_dict[plant])
|
||||||
|
|
||||||
def return_plant(self,plant_name):
|
def return_plant(self,plant_name):
|
||||||
return self.plants_image_dict[plant_name]
|
return (plant_name,self.plants_image_dict[plant_name])
|
8
Pole.py
8
Pole.py
@ -4,7 +4,7 @@ import Colors
|
|||||||
import pygame
|
import pygame
|
||||||
import time
|
import time
|
||||||
import Ui
|
import Ui
|
||||||
|
import math
|
||||||
|
|
||||||
class Pole:
|
class Pole:
|
||||||
def __init__(self,screen,image_loader):
|
def __init__(self,screen,image_loader):
|
||||||
@ -51,3 +51,9 @@ class Pole:
|
|||||||
|
|
||||||
def is_valid_move(self, coordinates):
|
def is_valid_move(self, coordinates):
|
||||||
return coordinates in self.slot_dict
|
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()
|
14
Roslina.py
14
Roslina.py
@ -1,3 +1,7 @@
|
|||||||
|
import Stan
|
||||||
|
import Srodek
|
||||||
|
import random
|
||||||
|
|
||||||
class Roslina:
|
class Roslina:
|
||||||
nazwa = None #[string]
|
nazwa = None #[string]
|
||||||
stan = None #[Stan]
|
stan = None #[Stan]
|
||||||
@ -36,6 +40,13 @@ class Roslina:
|
|||||||
self.stan = stan
|
self.stan = stan
|
||||||
self.srodek = srodek
|
self.srodek = srodek
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self,nazwa):
|
||||||
|
self.nazwa=nazwa
|
||||||
|
self.stan=Stan.Stan()
|
||||||
|
self.stan.set_random()
|
||||||
|
self.srodek=None
|
||||||
|
|
||||||
def checkSrodek(self):
|
def checkSrodek(self):
|
||||||
#może wykorzystać AI do porównywania zdjęć
|
#może wykorzystać AI do porównywania zdjęć
|
||||||
|
|
||||||
@ -66,3 +77,6 @@ class Roslina:
|
|||||||
self.doAkcja()
|
self.doAkcja()
|
||||||
self.stan.checkStan()
|
self.stan.checkStan()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def report_status(self):
|
||||||
|
return f"Nazwa rosliny: {self.nazwa} "+self.stan.report_all()
|
9
Slot.py
9
Slot.py
@ -3,6 +3,7 @@ import displayControler as dCon
|
|||||||
import Colors
|
import Colors
|
||||||
import random
|
import random
|
||||||
import Image
|
import Image
|
||||||
|
import Roslina
|
||||||
|
|
||||||
BORDER_THICKNESS=1 #Has to be INT value
|
BORDER_THICKNESS=1 #Has to be INT value
|
||||||
class Slot:
|
class Slot:
|
||||||
@ -10,7 +11,7 @@ class Slot:
|
|||||||
self.x_axis=x_axis
|
self.x_axis=x_axis
|
||||||
self.y_axis=y_axis
|
self.y_axis=y_axis
|
||||||
self.plant_image = None
|
self.plant_image = None
|
||||||
self.plant=color #TODO CHANGE IT BY HOOKING PLANT CLASS
|
self.plant=None
|
||||||
self.screen=screen
|
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.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
|
self.image_loader=image_loader
|
||||||
@ -28,7 +29,8 @@ class Slot:
|
|||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def set_random_plant(self):
|
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()
|
self.set_image()
|
||||||
|
|
||||||
def set_image(self):
|
def set_image(self):
|
||||||
@ -40,3 +42,6 @@ class Slot:
|
|||||||
|
|
||||||
def random_plant(self): #Probably will not be used later only for demo purpouse
|
def random_plant(self): #Probably will not be used later only for demo purpouse
|
||||||
return self.image_loader.return_random_plant()
|
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
12
Stan.py
@ -1,4 +1,5 @@
|
|||||||
import Akcja
|
import Akcja
|
||||||
|
import random
|
||||||
|
|
||||||
class Stan:
|
class Stan:
|
||||||
nawodnienie = None #[int] 0-100 (0-60: trzeba podlać), spada w zaleznosci od rosliny: aktualizowane bedzie "w tle"
|
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.wzrost = wzrost
|
||||||
self.choroba = choroba
|
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):
|
def checkStan(self):
|
||||||
# sprawdza stan rośliny i podejmuje akcje jeśli potrzebna
|
# sprawdza stan rośliny i podejmuje akcje jeśli potrzebna
|
||||||
@ -34,3 +43,6 @@ class Stan:
|
|||||||
else:
|
else:
|
||||||
self.akcja = None
|
self.akcja = None
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def report_all(self):
|
||||||
|
return f"Nawodnienie: {self.nawodnienie} Zyznosc: {self.zyznosc} Wzrost: {self.wzrost} Choroba: {self.choroba}"
|
Loading…
Reference in New Issue
Block a user