traktor slot i klasa osprzet

This commit is contained in:
Paulina Smierzchalska 2024-03-23 21:00:08 +01:00
parent 24fe7c40fc
commit 968e9641d7
9 changed files with 179 additions and 38 deletions

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

93
.idea/workspace.xml Normal file
View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="49f52dc2-4e9b-4657-a917-3f29e32eba3d" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Osprzet.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/App.py" beforeDir="false" afterPath="$PROJECT_DIR$/App.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Pole.py" beforeDir="false" afterPath="$PROJECT_DIR$/Pole.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Slot.py" beforeDir="false" afterPath="$PROJECT_DIR$/Slot.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Tractor.py" beforeDir="false" afterPath="$PROJECT_DIR$/Tractor.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="ram" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="HighlightingSettingsPerFile">
<setting file="file://$PROJECT_DIR$/main.py" root0="FORCE_HIGHLIGHTING" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2dsSuIBIc3Ixilc4jNL6FVW03E3" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Git.Branch.Popup.ShowAllRemotes&quot;: &quot;true&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/Paulina/Documents/STUDIA/ROK II SEMESTR IV/AI/AI_PROJECT&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable&quot;
}
}</component>
<component name="RunManager">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="AI_PROJECT" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="C:\Users\Paulina\Documents\STUDIA\pythonProject\venv\Scripts\python.exe" />
<option name="SDK_NAME" value="Python 3.9 (pythonProject)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="49f52dc2-4e9b-4657-a917-3f29e32eba3d" name="Changes" comment="" />
<created>1710795513420</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1710795513420</updated>
</task>
<servers />
</component>
</project>

19
App.py
View File

@ -5,22 +5,22 @@ import Pole
import time import time
import displayControler as dCon import displayControler as dCon
import Image import Image
import Osprzet
pygame.init() pygame.init()
screen = pygame.display.set_mode((dCon.getScreenWidth(), dCon.getScreenHeihgt())) screen = pygame.display.set_mode((dCon.getScreenWidth(), dCon.getScreenHeihgt()))
#Tractor creation
traktor=Tractor.Tractor(0,0,screen)
image_loader=Image.Image() image_loader=Image.Image()
image_loader.load_images() image_loader.load_images()
pole=Pole.Pole(screen,image_loader) 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 def init_demo(): #Demo purpose
pole.draw_grid()
traktor.draw_tractor() traktor.draw_tractor()
time.sleep(2) time.sleep(2)
pole.randomize_colors() pole.randomize_colors()
@ -34,7 +34,6 @@ def init_demo(): #Demo purpose
def init(demo): def init(demo):
screen.fill(Colors.WHITE)
pygame.display.update() pygame.display.update()
if(demo==True): if(demo==True):
init_demo() init_demo()
@ -42,8 +41,10 @@ def init(demo):
def demo_move(): def demo_move():
pole.get_slot_from_cord((traktor.x_axis,traktor.y_axis)).redraw_image() current_slot = traktor.slot
traktor.random_move() if current_slot:
current_slot.redraw_image() # Przerysowanie obrazu dla aktualnego slotu
traktor.random_move(pole)

14
Osprzet.py Normal file
View File

@ -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

View File

@ -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) 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) 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

View File

@ -9,6 +9,7 @@ class Slot:
def __init__(self,x_axis,y_axis,color,screen,image_loader): 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.plant_image = None
self.plant=color #TODO CHANGE IT BY HOOKING PLANT CLASS self.plant=color #TODO CHANGE IT BY HOOKING PLANT CLASS
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)
@ -31,8 +32,10 @@ class Slot:
self.set_image() self.set_image()
def set_image(self): def set_image(self):
self.screen.blit(self.plant,(self.x_axis*dCon.CUBE_SIZE,self.y_axis*dCon.CUBE_SIZE)) if self.plant_image is None:
pygame.draw.rect(self.screen,Colors.BLACK,self.field,BORDER_THICKNESS) 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 def random_plant(self): #Probably will not be used later only for demo purpouse

View File

@ -2,41 +2,47 @@ 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): self.draw_tractor()
if(dCon.isValidMove(self.x_axis, self.y_axis - 1)):
print("Ruch w gore") def random_move(self, pole):
self.y_axis=self.y_axis-1 directions = ["right", "left", "down", "up"]
self.draw_tractor() direction = random.choice(directions)
self.move_tractor(pole, direction)
def random_move(self): #to tak zrobiłam już na później, może się przyda
x=random.randint(0,3) def change_osprzet(self, new_osprzet):
self.move_tractor(x) 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")