commit
05e028c171
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
|
.idea/
|
47
Akcja.py
Normal file
47
Akcja.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import Srodek
|
||||||
|
|
||||||
|
|
||||||
|
#w przyszłości trzeba przenieść definicję środków do innego pliku inicjalizującego
|
||||||
|
class Akcja:
|
||||||
|
srodki = [] #lista obiektów klasy Srodek
|
||||||
|
benefits = [] #lista przechowująca benefity płynące z wykonania akcji
|
||||||
|
|
||||||
|
def __init__(self, typ):
|
||||||
|
self.typ = typ
|
||||||
|
if self.typ == "nawodnienie":
|
||||||
|
self.srodki.append(Srodek.Srodek(1, "woda", "woda"))
|
||||||
|
self.srodki.append(Srodek.Srodek(1.5, "powerade", "woda")) #nawadnia lepiej niż woda
|
||||||
|
self.benefits.append(typ)
|
||||||
|
self.benefits.append(100)
|
||||||
|
if self.typ == "zyznosc":
|
||||||
|
self.srodki.append(Srodek.Srodek(2, "obornik", "nawoz"))
|
||||||
|
self.srodki.append(Srodek.Srodek(3, "azotan", "nawoz"))
|
||||||
|
self.srodki.append(Srodek.Srodek(4, "wapno", "nawoz"))
|
||||||
|
self.srodki.append(Srodek.Srodek(5, "superfosfat", "nawoz"))
|
||||||
|
self.benefits.append(typ)
|
||||||
|
self.benefits.append(100)
|
||||||
|
if self.typ == "wzrost":
|
||||||
|
self.srodki.append(Srodek.Srodek(6, "witaminy", "odzywka"))
|
||||||
|
self.srodki.append(Srodek.Srodek(7, "aminokwasy", "odzywka"))
|
||||||
|
self.srodki.append(Srodek.Srodek(8, "algi morskie", "odzywka"))
|
||||||
|
self.benefits.append(typ)
|
||||||
|
self.benefits.append(20)
|
||||||
|
if self.typ == "grzyb":
|
||||||
|
self.srodki.append(Srodek.Srodek(9, "mankozeb", "ochrona"))
|
||||||
|
self.srodki.append(Srodek.Srodek(10, "czosnek", "ochrona")) #tak czosnek zabija grzyby
|
||||||
|
self.benefits.append("choroba")
|
||||||
|
self.benefits.append("brak")
|
||||||
|
if self.typ == "bakteria":
|
||||||
|
self.srodki.append(Srodek.Srodek(11, "miedź", "ochrona"))
|
||||||
|
self.srodki.append(Srodek.Srodek(12, "streptomycyna ", "ochrona"))
|
||||||
|
self.benefits.append("choroba")
|
||||||
|
self.benefits.append("brak")
|
||||||
|
if self.typ == "pasożyt":
|
||||||
|
self.srodki.append(Srodek.Srodek(13, "Cyjantraniliprol", "ochrona"))
|
||||||
|
self.srodki.append(Srodek.Srodek(14, "Permetryna", "ochrona"))
|
||||||
|
self.srodki.append(Srodek.Srodek(15, "Abamektyna", "ochrona"))
|
||||||
|
self.benefits.append("choroba")
|
||||||
|
self.benefits.append("brak")
|
||||||
|
|
||||||
|
def getBenefit(self):
|
||||||
|
return self.benefits
|
59
App.py
Normal file
59
App.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import pygame
|
||||||
|
import Colors
|
||||||
|
import Tractor
|
||||||
|
import Pole
|
||||||
|
import time
|
||||||
|
import displayControler as dCon
|
||||||
|
import Image
|
||||||
|
import Osprzet
|
||||||
|
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
screen = pygame.display.set_mode((dCon.getScreenWidth(), dCon.getScreenHeihgt()))
|
||||||
|
|
||||||
|
image_loader=Image.Image()
|
||||||
|
image_loader.load_images()
|
||||||
|
pole=Pole.Pole(screen,image_loader)
|
||||||
|
pole.draw_grid() #musi byc tutaj wywołane ponieważ inicjalizuje sloty do slownika
|
||||||
|
|
||||||
|
#Tractor creation
|
||||||
|
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()
|
||||||
|
traktor.draw_tractor()
|
||||||
|
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):
|
||||||
|
init_demo()
|
||||||
|
#TODO: Implement
|
||||||
|
|
||||||
|
|
||||||
|
def demo_move():
|
||||||
|
current_slot = traktor.slot
|
||||||
|
if current_slot:
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
14
Colors.py
Normal file
14
Colors.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import random
|
||||||
|
BLACK = (0, 0, 0)
|
||||||
|
BROWN = (139, 69, 19)
|
||||||
|
WHITE = (255, 255, 255)
|
||||||
|
RED=(255,0,0)
|
||||||
|
GREEN=(0,255,0)
|
||||||
|
|
||||||
|
def random_color():
|
||||||
|
x=random.randint(0,3)
|
||||||
|
switcher={0:BROWN,
|
||||||
|
1:GREEN,
|
||||||
|
2:RED,
|
||||||
|
3:WHITE}
|
||||||
|
return switcher[x]
|
29
Image.py
Normal file
29
Image.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import pygame
|
||||||
|
import displayControler as dCon
|
||||||
|
import random
|
||||||
|
|
||||||
|
class Image:
|
||||||
|
def __init__(self):
|
||||||
|
self.plants_image_dict={}
|
||||||
|
self.tractor_image=None
|
||||||
|
def load_images(self):
|
||||||
|
files_plants={0:"borowka",
|
||||||
|
1:"kukurydza",
|
||||||
|
2:"pszenica",
|
||||||
|
3:"slonecznik",
|
||||||
|
4:"winogrono",
|
||||||
|
5:"ziemniak"}
|
||||||
|
for index in files_plants:
|
||||||
|
plant_image=pygame.image.load("images/plants/"+files_plants[index]+".jpg")
|
||||||
|
plant_image=pygame.transform.scale(plant_image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
||||||
|
self.plants_image_dict[files_plants[index]]=plant_image
|
||||||
|
tractor_image=pygame.image.load("images/traktor.png")
|
||||||
|
tractor_image=pygame.transform.scale(tractor_image,(dCon.CUBE_SIZE,dCon.CUBE_SIZE))
|
||||||
|
def return_random_plant(self):
|
||||||
|
x=random.randint(0,5)
|
||||||
|
keys=list(self.plants_image_dict.keys())
|
||||||
|
plant=keys[x]
|
||||||
|
return (plant,self.plants_image_dict[plant])
|
||||||
|
|
||||||
|
def return_plant(self,plant_name):
|
||||||
|
return (plant_name,self.plants_image_dict[plant_name])
|
19
Osprzet.py
Normal file
19
Osprzet.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import Akcja
|
||||||
|
class Osprzet:
|
||||||
|
def __init__(self, id, marka, model, akcje = None):
|
||||||
|
self.id = id
|
||||||
|
self.marka = marka
|
||||||
|
self.model = model
|
||||||
|
if akcje is None:
|
||||||
|
self.akcje = []
|
||||||
|
else:
|
||||||
|
self.akcje = akcje
|
||||||
|
|
||||||
|
|
||||||
|
plug = Osprzet(1,'Bomet', 'U031')
|
||||||
|
siewnik = Osprzet(2, "Amazone", "12001-C")
|
||||||
|
rozsiewacz = Osprzet(3, 'John Deere', 'TF 1500', [Akcja.Akcja("zyznosc")])
|
||||||
|
opryskiwacz = Osprzet(4, 'John Deere', 'M720', [Akcja.Akcja("grzyb"), Akcja.Akcja("bakterie"), Akcja.Akcja("nawodnienie"), Akcja.Akcja("wzrost")])
|
||||||
|
header = Osprzet(5, 'John Deere', 'X350R')
|
||||||
|
#jak istnieją jakieś bardziej profesjonalne nazwy czy lepsze to śmiało zmieńcie
|
||||||
|
|
59
Pole.py
Normal file
59
Pole.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import displayControler as dCon
|
||||||
|
import Slot
|
||||||
|
import Colors
|
||||||
|
import pygame
|
||||||
|
import time
|
||||||
|
import Ui
|
||||||
|
import math
|
||||||
|
|
||||||
|
class Pole:
|
||||||
|
def __init__(self,screen,image_loader):
|
||||||
|
self.screen=screen
|
||||||
|
self.slot_dict={} #Slot are stored in dictionary with key being a Tuple of x and y coordinates so top left slot key is (0,0) and value is slot object
|
||||||
|
self.ui=Ui.Ui(screen)
|
||||||
|
self.image_loader=image_loader
|
||||||
|
|
||||||
|
def get_slot_from_cord(self,coordinates):
|
||||||
|
(x_axis,y_axis)=coordinates
|
||||||
|
return self.slot_dict[(x_axis,y_axis)]
|
||||||
|
|
||||||
|
def set_slot(self,coodrinates,slot): #set slot in these coordinates
|
||||||
|
(x_axis,y_axis)=coodrinates
|
||||||
|
self.slot_dict[(x_axis,y_axis)]=slot
|
||||||
|
|
||||||
|
def get_slot_dict(self): #returns whole slot_dict
|
||||||
|
return self.slot_dict
|
||||||
|
|
||||||
|
#Draw grid and tractor (new one)
|
||||||
|
def draw_grid(self):
|
||||||
|
for x in range(0,dCon.NUM_X): #Draw all cubes in X axis
|
||||||
|
for y in range(0,dCon.NUM_Y): #Draw all cubes in Y axis
|
||||||
|
new_slot=Slot.Slot(x,y,Colors.BROWN,self.screen,self.image_loader) #Creation of empty slot
|
||||||
|
self.set_slot((x,y),new_slot) #Adding slots to dict
|
||||||
|
slot_dict=self.get_slot_dict()
|
||||||
|
for coordinates in slot_dict:
|
||||||
|
slot_dict[coordinates].draw()
|
||||||
|
|
||||||
|
def randomize_colors(self):
|
||||||
|
pygame.display.update()
|
||||||
|
time.sleep(3)
|
||||||
|
self.ui.render_text("Randomizing Crops")
|
||||||
|
for coordinates in self.slot_dict:
|
||||||
|
self.slot_dict[coordinates].set_random_plant()
|
||||||
|
|
||||||
|
def change_color_of_slot(self,coordinates,color): #Coordinates must be tuple (x,y) (left top slot has cord (0,0) ), color has to be from defined in Colors.py or custom in RGB value (R,G,B)
|
||||||
|
self.get_slot_from_cord(coordinates).color_change(color)
|
||||||
|
|
||||||
|
def get_neighbor(self, slot, dx, dy):
|
||||||
|
neighbor_x = slot.x_axis + dx
|
||||||
|
neighbor_y = slot.y_axis + dy
|
||||||
|
return self.get_slot_from_cord((neighbor_x, neighbor_y))
|
||||||
|
|
||||||
|
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()
|
82
Roslina.py
Normal file
82
Roslina.py
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import Stan
|
||||||
|
import Srodek
|
||||||
|
import random
|
||||||
|
|
||||||
|
class Roslina:
|
||||||
|
nazwa = None #[string]
|
||||||
|
stan = None #[Stan]
|
||||||
|
srodek = None #[List<Srodek>]
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Nawodnienie (update co 30s):
|
||||||
|
- pszenica: -8
|
||||||
|
- kukurydza: -7
|
||||||
|
- ziemniak: -6
|
||||||
|
- słonecznik: -5
|
||||||
|
- borówka: -4
|
||||||
|
- winogrono: -4
|
||||||
|
|
||||||
|
Żyzność (update co 30s):
|
||||||
|
- pszenica: -7
|
||||||
|
- kukurydza: -4
|
||||||
|
- ziemniak: -5
|
||||||
|
- słonecznik: -3
|
||||||
|
- borówka: -5
|
||||||
|
- winogrono: -4
|
||||||
|
|
||||||
|
Wzrost (update co 30s):
|
||||||
|
- pszenica: +8
|
||||||
|
- kukurydza: +4
|
||||||
|
- ziemniak: +5
|
||||||
|
- słonecznik: +3
|
||||||
|
- borówka: +5
|
||||||
|
- winogrono: +4
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, nazwa, stan, srodek):
|
||||||
|
self.nazwa = nazwa
|
||||||
|
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ęć
|
||||||
|
|
||||||
|
for i in self.srodek:
|
||||||
|
for j in self.stan.akcja.srodki:
|
||||||
|
if i == j:
|
||||||
|
return i
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def doAkcja(self):
|
||||||
|
# sprawdza jaki srodek do danej akcji i jaki z nich może być użyty przy tej roślinie
|
||||||
|
# robi akcje
|
||||||
|
# aktualizuje dane o stanie i zdjęcie w zależności od wykonanej czynności (benefits w klasie akcja) -> (self.stan.akcja.benefits)
|
||||||
|
|
||||||
|
x = self.checkSrodek()
|
||||||
|
# robi akcje
|
||||||
|
setattr(self.stan, self.stan.akcja.benefits[0], self.stan.akcja.benefits[1])
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def isAkcja(self):
|
||||||
|
# sprawdza czy jakaś akcja musi być wykonana, jeżeli tak, to ją wywołuje
|
||||||
|
# sprawdza czy jeszcze coś trzeba zrobić
|
||||||
|
|
||||||
|
self.stan.checkStan()
|
||||||
|
while self.stan.akcja != None:
|
||||||
|
self.doAkcja()
|
||||||
|
self.stan.checkStan()
|
||||||
|
return
|
||||||
|
|
||||||
|
def report_status(self):
|
||||||
|
return f"Nazwa rosliny: {self.nazwa} "+self.stan.report_all()
|
41
Slot.py
41
Slot.py
@ -1,20 +1,47 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import displayControler as dCon
|
import displayControler as dCon
|
||||||
|
import Colors
|
||||||
|
import random
|
||||||
|
import Image
|
||||||
|
import Roslina
|
||||||
|
|
||||||
BLACK=(0,0,0)
|
|
||||||
BORDER_COLOR=BLACK
|
|
||||||
BORDER_THICKNESS=1 #Has to be INT value
|
BORDER_THICKNESS=1 #Has to be INT value
|
||||||
class Slot:
|
class Slot:
|
||||||
def __init__(self,x_axis,y_axis,color,screen): #TODO crop and related to it things handling. for now as a place holder crop=>color
|
def __init__(self,x_axis,y_axis,color,screen,image_loader):
|
||||||
self.x_axis=x_axis
|
self.x_axis=x_axis
|
||||||
self.y_axis=y_axis
|
self.y_axis=y_axis
|
||||||
self.color=color
|
self.plant_image = None
|
||||||
|
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
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
pygame.draw.rect(self.screen,self.color,self.field,0) #Draw field
|
pygame.draw.rect(self.screen,Colors.BROWN,self.field,0) #Draw field
|
||||||
pygame.draw.rect(self.screen,BLACK,self.field,BORDER_THICKNESS) #Draw border
|
pygame.draw.rect(self.screen,Colors.BLACK,self.field,BORDER_THICKNESS) #Draw border
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
|
def redraw_image(self):
|
||||||
|
self.set_image()
|
||||||
|
|
||||||
def color_change(self,color):
|
def color_change(self,color):
|
||||||
self.color=color
|
self.plant=color
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
|
def set_random_plant(self):
|
||||||
|
(plant_name,self.plant_image)=self.random_plant()
|
||||||
|
self.plant=Roslina.Roslina(plant_name)
|
||||||
|
self.set_image()
|
||||||
|
|
||||||
|
def set_image(self):
|
||||||
|
if self.plant_image is None:
|
||||||
|
self.plant_image = self.image_loader.return_random_plant()
|
||||||
|
self.screen.blit(self.plant_image, (self.x_axis * dCon.CUBE_SIZE, self.y_axis * dCon.CUBE_SIZE))
|
||||||
|
pygame.draw.rect(self.screen, Colors.BLACK, self.field, BORDER_THICKNESS)
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
5
Srodek.py
Normal file
5
Srodek.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class Srodek:
|
||||||
|
def __init__(self, id, nazwa, typ):
|
||||||
|
self.id = id
|
||||||
|
self.nazwa = nazwa
|
||||||
|
self.typ = typ
|
48
Stan.py
Normal file
48
Stan.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import Akcja
|
||||||
|
import random
|
||||||
|
|
||||||
|
class Stan:
|
||||||
|
nawodnienie = None #[int] 0-100 (0-60: trzeba podlać), spada w zaleznosci od rosliny: aktualizowane bedzie "w tle"
|
||||||
|
zyznosc = None #[int] 0-100 (0-60: trzeba użyźnić), spada w zaleznosci od rosliny: aktualizowane bedzie "w tle"
|
||||||
|
wzrost = None #[int] 0-100 (75-100: scinanie), wzrasta w zaleznosci od rosliny: aktualizowane bedzie "w tle"
|
||||||
|
choroba = None #[string] brak, grzyb, bakteria, pasożyt
|
||||||
|
akcja = None #[Akcja]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, nawodnienie, zyznosc, wzrost, choroba):
|
||||||
|
self.nawodnienie = nawodnienie
|
||||||
|
self.zyznosc = zyznosc
|
||||||
|
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
|
||||||
|
|
||||||
|
if self.nawodnienie <= 60:
|
||||||
|
self.akcja = Akcja.Akcja("nawodnienie")
|
||||||
|
return
|
||||||
|
elif self.zyznosc <= 60:
|
||||||
|
self.akcja = Akcja.Akcja("zyznosc")
|
||||||
|
return
|
||||||
|
elif self.wzrost >= 75:
|
||||||
|
self.akcja = Akcja.Akcja("wzrost")
|
||||||
|
return
|
||||||
|
elif self.choroba != "brak":
|
||||||
|
self.akcja = Akcja.Akcja(self.choroba)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.akcja = None
|
||||||
|
return
|
||||||
|
|
||||||
|
def report_all(self):
|
||||||
|
return f"Nawodnienie: {self.nawodnienie} Zyznosc: {self.zyznosc} Wzrost: {self.wzrost} Choroba: {self.choroba}"
|
61
Tractor.py
61
Tractor.py
@ -2,41 +2,52 @@ import pygame
|
|||||||
import random
|
import random
|
||||||
import displayControler as dCon
|
import displayControler as dCon
|
||||||
import Slot
|
import Slot
|
||||||
|
import Osprzet
|
||||||
|
|
||||||
class Tractor:
|
class Tractor:
|
||||||
def __init__(self,x_axis,y_axis,screen):
|
def __init__(self,slot,screen, osprzet):
|
||||||
self.x_axis=x_axis
|
|
||||||
self.y_axis=y_axis
|
|
||||||
self.tractor_image = pygame.image.load('images/traktor.png')
|
self.tractor_image = pygame.image.load('images/traktor.png')
|
||||||
self.tractor_image = pygame.transform.scale(self.tractor_image, (dCon.CUBE_SIZE, dCon.CUBE_SIZE))
|
self.tractor_image = pygame.transform.scale(self.tractor_image, (dCon.CUBE_SIZE, dCon.CUBE_SIZE))
|
||||||
self.screen=screen
|
self.screen=screen
|
||||||
self.slot=None
|
self.slot=slot
|
||||||
|
self.osprzet = osprzet
|
||||||
|
|
||||||
def draw_tractor(self):
|
def draw_tractor(self):
|
||||||
self.screen.blit(self.tractor_image, (self.x_axis*dCon.CUBE_SIZE,self.y_axis*dCon.CUBE_SIZE))
|
self.screen.blit(self.tractor_image, (self.slot.x_axis*dCon.CUBE_SIZE,self.slot.y_axis*dCon.CUBE_SIZE))
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
|
||||||
def move_tractor(self,x):
|
def move_tractor(self, pole, direction):
|
||||||
if(x==0):
|
next_slot = None
|
||||||
if(dCon.isValidMove(self.x_axis + 1, self.y_axis)):
|
if direction == "right" and pole.is_valid_move((self.slot.x_axis + 1, self.slot.y_axis)):
|
||||||
print("Ruch w prawo")
|
next_slot = pole.get_neighbor(self.slot, 1, 0)
|
||||||
self.x_axis=self.x_axis+1
|
elif direction == "left" and pole.is_valid_move((self.slot.x_axis - 1, self.slot.y_axis)):
|
||||||
elif(x==1):
|
next_slot = pole.get_neighbor(self.slot, -1, 0)
|
||||||
if(dCon.isValidMove(self.x_axis - 1, self.y_axis)):
|
elif direction == "down" and pole.is_valid_move((self.slot.x_axis, self.slot.y_axis + 1)):
|
||||||
print("Ruch w lewo")
|
next_slot = pole.get_neighbor(self.slot, 0, 1)
|
||||||
self.x_axis=self.x_axis-1
|
elif direction == "up" and pole.is_valid_move((self.slot.x_axis, self.slot.y_axis - 1)):
|
||||||
elif(x==2):
|
next_slot = pole.get_neighbor(self.slot, 0, -1)
|
||||||
if(dCon.isValidMove(self.x_axis, self.y_axis + 1)):
|
|
||||||
print("Ruch w dol")
|
if next_slot:
|
||||||
self.y_axis=self.y_axis+1
|
self.slot = next_slot
|
||||||
elif(x==3):
|
|
||||||
if(dCon.isValidMove(self.x_axis, self.y_axis - 1)):
|
|
||||||
print("Ruch w gore")
|
|
||||||
self.y_axis=self.y_axis-1
|
|
||||||
self.draw_tractor()
|
self.draw_tractor()
|
||||||
|
|
||||||
|
def random_move(self, pole):
|
||||||
|
directions = ["right", "left", "down", "up"]
|
||||||
|
direction = random.choice(directions)
|
||||||
|
self.move_tractor(pole, direction)
|
||||||
|
|
||||||
def random_move(self):
|
|
||||||
x=random.randint(0,3)
|
|
||||||
self.move_tractor(x)
|
|
||||||
|
|
||||||
|
#to tak zrobiłam już na później, może się przyda
|
||||||
|
def change_osprzet(self, new_osprzet):
|
||||||
|
self.osprzet = new_osprzet
|
||||||
|
|
||||||
|
def print_osprzet_info(self):
|
||||||
|
print("ID:", self.osprzet.id)
|
||||||
|
print("Marka:", self.osprzet.marka)
|
||||||
|
print("Model:", self.osprzet.model)
|
||||||
|
if self.osprzet.akcje:
|
||||||
|
print("Akcje:")
|
||||||
|
for akcja in self.osprzet.akcje:
|
||||||
|
print("- Typ:", akcja.typ)
|
||||||
|
else:
|
||||||
|
print("Brak akcji przypisanych do tego sprzętu.")
|
16
Ui.py
Normal file
16
Ui.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import pygame
|
||||||
|
import displayControler as dCon
|
||||||
|
import Colors
|
||||||
|
|
||||||
|
|
||||||
|
class Ui:
|
||||||
|
def __init__(self,screen):
|
||||||
|
self.screen=screen
|
||||||
|
self.font='freesansbold.ttf' #Feel free to change it :D
|
||||||
|
self.font_size=int(32)
|
||||||
|
def render_text(self,string_to_print):
|
||||||
|
font=pygame.font.Font(self.font,self.font_size)
|
||||||
|
text=font.render(string_to_print,True,Colors.BLACK,Colors.WHITE)
|
||||||
|
textRect=text.get_rect()
|
||||||
|
textRect.center=(dCon.getScreenWidth() // 2,dCon.getScreenHeihgt() // 2)
|
||||||
|
self.screen.blit(text,textRect)
|
BIN
images/plants/borowka.jpg
Normal file
BIN
images/plants/borowka.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 190 KiB |
BIN
images/plants/kukurydza.jpg
Normal file
BIN
images/plants/kukurydza.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 MiB |
BIN
images/plants/pszenica.jpg
Normal file
BIN
images/plants/pszenica.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 711 KiB |
BIN
images/plants/slonecznik.jpg
Normal file
BIN
images/plants/slonecznik.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 672 KiB |
BIN
images/plants/winogrono.jpg
Normal file
BIN
images/plants/winogrono.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 161 KiB |
BIN
images/plants/ziemniak.jpg
Normal file
BIN
images/plants/ziemniak.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 MiB |
94
main.py
94
main.py
@ -1,93 +1,3 @@
|
|||||||
import pygame
|
import App
|
||||||
import Slot
|
|
||||||
import Tractor
|
|
||||||
import random
|
|
||||||
import time
|
|
||||||
import displayControler as dCon
|
|
||||||
|
|
||||||
|
|
||||||
pygame.init()
|
|
||||||
|
|
||||||
BLACK = (0, 0, 0)
|
|
||||||
BROWN = (139, 69, 19)
|
|
||||||
WHITE = (255, 255, 255)
|
|
||||||
RED=(255,0,0)
|
|
||||||
GREEN=(0,255,0)
|
|
||||||
|
|
||||||
screen = pygame.display.set_mode((dCon.getScreenWidth(), dCon.getScreenHeihgt()))
|
|
||||||
screen.fill(WHITE)
|
|
||||||
pygame.display.update()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Tractor creation
|
|
||||||
traktor=Tractor.Tractor(0,0,screen)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SLOT_DICT={} #Slot are stored in dictionary with key being a Tuple of x and y coordinates so top left slot key is (0,0) and value is slot object
|
|
||||||
"""#Draw grid and tractor (old one)
|
|
||||||
def draw_grid():
|
|
||||||
for x in range(0, 8):
|
|
||||||
pygame.draw.line(screen, BLACK, (x*CUBE_SIZE, 0), (x*CUBE_SIZE, HEIGHT)) #We got 8 lines in Y axis so to draw them we use x from range <0,7) to make slot manage easier
|
|
||||||
for y in range(0, 4):
|
|
||||||
pygame.draw.line(screen, BLACK, (0, y*CUBE_SIZE), (WIDTH, y*CUBE_SIZE)) #We got 4 lines in X axis so to draw them we use y from range <0,4) to make slot manage easier
|
|
||||||
|
|
||||||
# Draw tractor
|
|
||||||
tractor_image = pygame.image.load('images/traktor.png')
|
|
||||||
tractor_image = pygame.transform.scale(tractor_image, (CUBE_SIZE, CUBE_SIZE))
|
|
||||||
screen.blit(tractor_image, (CUBE_SIZE - 128, CUBE_SIZE - 128))"""
|
|
||||||
|
|
||||||
|
|
||||||
#Draw grid and tractor (new one)
|
|
||||||
def draw_grid():
|
|
||||||
for x in range(0,dCon.NUM_X): #We got 8 cubes in X axis so we use for from 0 to 7 do draw them all
|
|
||||||
for y in range(0,dCon.NUM_Y): #We got 4 cubes in Y axis so we use for from 0 to 3 to draw them all
|
|
||||||
new_slot=Slot.Slot(x,y,BROWN,screen) #Creation of empty slot
|
|
||||||
SLOT_DICT[(x,y)]=new_slot #Adding slots to dict
|
|
||||||
for entity in SLOT_DICT:
|
|
||||||
SLOT_DICT[entity].draw()
|
|
||||||
traktor.draw_tractor()
|
|
||||||
|
|
||||||
def change_color_of_slot(coordinates,color): #Coordinates must be tuple (x,y) x from range 0,7 and y in range 0,3 (left top slot has cord (0,0) ), color has to be from defined or custom in RGB value (R,G,B)
|
|
||||||
SLOT_DICT[coordinates].color_change(color)
|
|
||||||
|
|
||||||
def random_color():
|
|
||||||
x=random.randint(0,3)
|
|
||||||
switcher={0:BROWN,
|
|
||||||
1:GREEN,
|
|
||||||
2:RED,
|
|
||||||
3:WHITE}
|
|
||||||
return switcher[x]
|
|
||||||
|
|
||||||
#Demo purpose, can be reused for photos of crops in the future(?)
|
|
||||||
def randomize_colors():
|
|
||||||
font=pygame.font.Font('freesansbold.ttf',32)
|
|
||||||
text=font.render('Randomizing crops',True,BLACK,WHITE)
|
|
||||||
textRect=text.get_rect()
|
|
||||||
textRect.center=(dCon.getScreenWidth() // 2,dCon.getScreenHeihgt() // 2)
|
|
||||||
screen.blit(text,textRect)
|
|
||||||
pygame.display.update()
|
|
||||||
time.sleep(3)
|
|
||||||
for coordinates in SLOT_DICT:
|
|
||||||
SLOT_DICT[coordinates].color_change(random_color())
|
|
||||||
traktor.draw_tractor()
|
|
||||||
|
|
||||||
def init_demo(): #Demo purpose
|
|
||||||
draw_grid()
|
|
||||||
time.sleep(2)
|
|
||||||
randomize_colors()
|
|
||||||
|
|
||||||
|
|
||||||
def demo_move():
|
|
||||||
SLOT_DICT[(traktor.x_axis,traktor.y_axis)].draw()
|
|
||||||
traktor.random_move()
|
|
||||||
init_demo()
|
|
||||||
while True:
|
|
||||||
time.sleep(1)
|
|
||||||
demo_move()
|
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.QUIT:
|
|
||||||
quit()
|
|
||||||
|
|
||||||
|
App.init(demo=True)#DEMO=TRUE WILL INIT DEMO MODE WITH RANDOM COLOR GEN
|
Loading…
Reference in New Issue
Block a user