From 968e9641d75ff25c35e82cc4ca58bdef9ab98546 Mon Sep 17 00:00:00 2001 From: Paulina Smierzchalska Date: Sat, 23 Mar 2024 21:00:08 +0100 Subject: [PATCH 1/6] traktor slot i klasa osprzet --- .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 4 + .idea/vcs.xml | 6 ++ .idea/workspace.xml | 93 +++++++++++++++++++ App.py | 19 ++-- Osprzet.py | 14 +++ Pole.py | 8 ++ Slot.py | 7 +- Tractor.py | 60 ++++++------ 9 files changed, 179 insertions(+), 38 deletions(-) create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 Osprzet.py diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d56657a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..4079059 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "keyToString": { + "Git.Branch.Popup.ShowAllRemotes": "true", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "last_opened_file_path": "C:/Users/Paulina/Documents/STUDIA/ROK II SEMESTR IV/AI/AI_PROJECT", + "settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" + } +} + + + + + + + + + + 1710795513420 + + + + \ No newline at end of file diff --git a/App.py b/App.py index 63222d9..d22af9b 100644 --- a/App.py +++ b/App.py @@ -5,22 +5,22 @@ import Pole import time import displayControler as dCon import Image +import Osprzet pygame.init() screen = pygame.display.set_mode((dCon.getScreenWidth(), dCon.getScreenHeihgt())) -#Tractor creation -traktor=Tractor.Tractor(0,0,screen) - - 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 - pole.draw_grid() +def init_demo(): #Demo purpose traktor.draw_tractor() time.sleep(2) pole.randomize_colors() @@ -34,7 +34,6 @@ def init_demo(): #Demo purpose def init(demo): - screen.fill(Colors.WHITE) pygame.display.update() if(demo==True): init_demo() @@ -42,8 +41,10 @@ def init(demo): def demo_move(): - pole.get_slot_from_cord((traktor.x_axis,traktor.y_axis)).redraw_image() - traktor.random_move() + current_slot = traktor.slot + if current_slot: + current_slot.redraw_image() # Przerysowanie obrazu dla aktualnego slotu + traktor.random_move(pole) diff --git a/Osprzet.py b/Osprzet.py new file mode 100644 index 0000000..25c9316 --- /dev/null +++ b/Osprzet.py @@ -0,0 +1,14 @@ +class Osprzet: + akcja = None + def __init__(self, id, marka, model): + self.id = id + self.marka = marka + self.model = model + + +plug = Osprzet(1,'Bomet', 'U031') +siewnik = Osprzet(2, "Amazone", "12001-C") +rozsiewacz = Osprzet(3, 'John Deere', 'TF 1500') +opryskiwacz = Osprzet(4, 'John Deere', 'M720') +header = Osprzet(5, 'John Deere', 'X350R') +#jak istnieją jakieś bardziej profesjonalne nazwy czy lepsze to śmiało zmieńcie \ No newline at end of file diff --git a/Pole.py b/Pole.py index 101f2ae..9500ad5 100644 --- a/Pole.py +++ b/Pole.py @@ -43,3 +43,11 @@ class Pole: 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 diff --git a/Slot.py b/Slot.py index 78d9f56..ec96a6a 100644 --- a/Slot.py +++ b/Slot.py @@ -9,6 +9,7 @@ class Slot: def __init__(self,x_axis,y_axis,color,screen,image_loader): 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.screen=screen self.field=pygame.Rect(self.x_axis*dCon.CUBE_SIZE,self.y_axis*dCon.CUBE_SIZE,dCon.CUBE_SIZE,dCon.CUBE_SIZE) @@ -31,8 +32,10 @@ class Slot: self.set_image() def set_image(self): - self.screen.blit(self.plant,(self.x_axis*dCon.CUBE_SIZE,self.y_axis*dCon.CUBE_SIZE)) - pygame.draw.rect(self.screen,Colors.BLACK,self.field,BORDER_THICKNESS) + 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 diff --git a/Tractor.py b/Tractor.py index adc48c6..bffbd6b 100644 --- a/Tractor.py +++ b/Tractor.py @@ -2,41 +2,47 @@ import pygame import random import displayControler as dCon import Slot +import Osprzet class Tractor: - def __init__(self,x_axis,y_axis,screen): - self.x_axis=x_axis - self.y_axis=y_axis + def __init__(self,slot,screen, osprzet): 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.screen=screen - self.slot=None + self.slot=slot + self.osprzet = osprzet 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() - def move_tractor(self,x): - if(x==0): - if(dCon.isValidMove(self.x_axis + 1, self.y_axis)): - print("Ruch w prawo") - self.x_axis=self.x_axis+1 - elif(x==1): - if(dCon.isValidMove(self.x_axis - 1, self.y_axis)): - print("Ruch w lewo") - self.x_axis=self.x_axis-1 - elif(x==2): - if(dCon.isValidMove(self.x_axis, self.y_axis + 1)): - print("Ruch w dol") - self.y_axis=self.y_axis+1 - 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() + def move_tractor(self, pole, direction): + next_slot = None + if direction == "right" and pole.is_valid_move((self.slot.x_axis + 1, self.slot.y_axis)): + next_slot = pole.get_neighbor(self.slot, 1, 0) + elif direction == "left" and pole.is_valid_move((self.slot.x_axis - 1, self.slot.y_axis)): + next_slot = pole.get_neighbor(self.slot, -1, 0) + elif direction == "down" and pole.is_valid_move((self.slot.x_axis, self.slot.y_axis + 1)): + next_slot = pole.get_neighbor(self.slot, 0, 1) + elif direction == "up" and pole.is_valid_move((self.slot.x_axis, self.slot.y_axis - 1)): + next_slot = pole.get_neighbor(self.slot, 0, -1) + + if next_slot: + self.slot = next_slot + 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) - \ No newline at end of file + #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): + if self.osprzet is not None: + print("Wyposazenie:", self.osprzet.marka, self.osprzet.model) + else: + print("Brak") \ No newline at end of file -- 2.20.1 From c55f2b88c38f4bc6dc2c857a8f9700217175f42f Mon Sep 17 00:00:00 2001 From: Paulina Smierzchalska Date: Sat, 23 Mar 2024 21:04:45 +0100 Subject: [PATCH 2/6] Dodano wpis do .gitignore --- .gitignore | 3 ++- .idea/workspace.xml | 11 ++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index ba0430d..8b29db5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -__pycache__/ \ No newline at end of file +__pycache__/ +.idea/ \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4079059..9788e63 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,15 +5,8 @@ - - - - - - - - - + +