From 5100e3e060cc7aac827e38dfe813f6695d637d5e Mon Sep 17 00:00:00 2001 From: Tomasz Adamczyk Date: Sun, 21 Mar 2021 12:40:13 +0100 Subject: [PATCH] testowanie ruchu --- .idea/vcs.xml | 6 +++ .idea/workspace.xml | 62 +++++++++++++++++++++---- __pycache__/definitions.cpython-37.pyc | Bin 0 -> 501 bytes __pycache__/field.cpython-37.pyc | Bin 0 -> 1413 bytes __pycache__/plant.cpython-37.pyc | Bin 0 -> 1883 bytes __pycache__/soil.cpython-37.pyc | Bin 0 -> 1227 bytes __pycache__/tractor.cpython-37.pyc | Bin 0 -> 1509 bytes definitions.py | 10 ++++ field.py | 22 +++++++++ plant.py | 27 +++++++++++ py.py | 60 +++++++++++++----------- soil.py | 17 +++++++ tractor.py | 21 +++++++++ 13 files changed, 189 insertions(+), 36 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 __pycache__/definitions.cpython-37.pyc create mode 100644 __pycache__/field.cpython-37.pyc create mode 100644 __pycache__/plant.cpython-37.pyc create mode 100644 __pycache__/soil.cpython-37.pyc create mode 100644 __pycache__/tractor.cpython-37.pyc create mode 100644 definitions.py create mode 100644 field.py create mode 100644 plant.py create mode 100644 soil.py create mode 100644 tractor.py diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /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 index bf7ab00..cd7d608 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,13 +1,27 @@ - + + + + + + + + + + - + - - + + - - + + - - + + - + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/__pycache__/definitions.cpython-37.pyc b/__pycache__/definitions.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e3d956114d7337ad3f2df96fccbfea2f49593796 GIT binary patch literal 501 zcmXv~OK#gR5GD1qY*$X=09|*hjSo;1MbpHs4Frx6t2ICfa0zj2%aufdR2K39at?c$ zD{-4me1&Y@2i z<7AQxD@ix%(PV_jqjs6O~lqxr_PIv~){yn^XBI>d+ z*}&_~_2>AP2BqUj=3H+-T?w8i+xl-jt&=rZ`BcdbB$bY5IagKm{@_@^GA+_7m4zOZ dwei28>xT@!Hs7cF2tM_xgUhGq^dn-Q{s)l!h%*2H literal 0 HcmV?d00001 diff --git a/__pycache__/field.cpython-37.pyc b/__pycache__/field.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..88d0924dea271e44cb89324695b920f67ac30564 GIT binary patch literal 1413 zcma)6%Wl&^6rJ%Sab8Uyuw%gvvgrpPQ~{M>7gcHyQWR;hd|gPflQQEtoW1wMjb z@|M3~#XV!YL`{o4*4#6mJHF?hnLB z{f9Fb0b_@H)MxC{fQF0# zjcAXtM`PM&?9%}qG7jj7`JR;i`(>O^y36qA)N-}Vlmdqd*a+FN&t}g` zI&Kz35>9SFbgQkygF;-^Dx^(yA~mLMf|Wts(*F`?>IPXGkO{dNR19`LvU5BQM7QBl z0@c0}5$NHzdZCLkEfHHVprFMc9hP(I+ D;wJRi literal 0 HcmV?d00001 diff --git a/__pycache__/plant.cpython-37.pyc b/__pycache__/plant.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..31ce42906a3c75b3a7bef8ebd04c91e36aaba9d7 GIT binary patch literal 1883 zcma)6OHbQC5MDcW;yif;8hU6^Z@F;cR#k|WLvIlhRF$GgTg&6p&^%z*PzCu`{!IUp zul*N2b-s-qOdgUq+L^U?;%~lhXXjJ1Sra@?j=p|7c7*tghisI1amG{cviU4XkoCm# zx7`UG`3nfT){sZ7)lnaBr{s`r<`*(W&e(*(yN)N84V_!cW zeI$PzJkEX&E@r_GUyU!+^d<}Kcf`%0RNMz`W)i zcuWI=#OCT}DyKm990-9cXgWp1pO?_Gtzwj*{{~8R}c(X>8TxfAoOd_c$rU5L8(s@BN2XU~P&8E;|lHjgy zkfaJpOz-OCP`92nFnh&G8>o~t*2|Zm3MS^8uUGLFd%bQ8Ee<_L%A_Xcm>cj2>xPtf z_x@i7gX7`Mxegr50CIccJ)M1%)CrqhJ< zt+=c;NXKv@O^3G~xytnTw+z4NLO~+VSb&KJqlu($mjm#a4g=3!)vc*jjpJ1~NW2GT zYp{@m|AIA!uqbH2*e%S@E+VQbeJe~&mK`n zVBYGzaSQ9=PFgGBaDfiB7Krs-fsdiW=k*#H0l literal 0 HcmV?d00001 diff --git a/__pycache__/tractor.cpython-37.pyc b/__pycache__/tractor.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..773f99d5dc9028a5e5d72bede8bc5f1314f4b471 GIT binary patch literal 1509 zcma)6O>fgc5Z$$%#QAE{Qi+Na*GQ;mgb*rJh)We!Y5*yUv{)XeO^D;LcA$>h6a6#% zC0{x57dSC*6PKiEn{2c*>z&X7k{Pd;E+I36dkx z6(0myWZwv~e_CBh@=UaxKO7frA2x4%)_iY=2Z7*~qHB>P>qc~KvdLlZP=Si<3sfSP zeUZvkVPB#u)!4gKrycfXYEYAXg?4F=eU+Xt>V8)0XwOd~?Sm*9Jo+*B_<#*bM_dUd zu9>JA$!m)QZ?@W6a=c|_@-mZY%g&rQ81*%FYlqD*p^NPP9v#2xeT)Mg_c~GN#k1#c z$qW5i`n7kO`WK!KPjxg5{3Pz3g`Q3pjC#qO+2JJ3T%`u%L827Sj&Zh-6*+4zmLBF| zAB520(Txg_xDrEfmhF}_1lbjM+7O(Z5`Sie^B_@|*bpQ8LeA_{B@Kkr+I>hS zvLfX+X?wgLRY~N~dTMT1o;=&!o~%kiA5|Yj<2bWFy+3(CXgQ3&2a2K}oe>V$T!B>nvJvhHekkP!>dn@uycr$^!`c1Jn z=`R@q)5-o4dSeBBI%&6Rc*A2a43x?$N`(o&*{CvKZr@FEB^t`&I}&_ literal 0 HcmV?d00001 diff --git a/definitions.py b/definitions.py new file mode 100644 index 0000000..6b50234 --- /dev/null +++ b/definitions.py @@ -0,0 +1,10 @@ +import os +import pygame +FPS = 1 +WHITE = ((255, 255, 255)) +WIDTH, HEIGHT = 1000, 1000 +WIN = pygame.display.set_mode((WIDTH, HEIGHT)) +TRACTOR = pygame.image.load(os.path.join('resources', 'tractor.png')) +TRACTOR_WIDTH, TRACTOR_HEIGHT = 100, 100 +TRACTOR = pygame.transform.scale(TRACTOR, (TRACTOR_WIDTH, TRACTOR_HEIGHT)) +VEL = 100 \ No newline at end of file diff --git a/field.py b/field.py new file mode 100644 index 0000000..297a377 --- /dev/null +++ b/field.py @@ -0,0 +1,22 @@ +class Field: + def __init__(self, x, y, plant, soil): + self.x = x + self.y = y + self.plant = plant + self.soil = soil + def get_x(self): + return self.x + def set_x(self, x): + self.x = x + def get_y(self): + return self.y + def set_y(self, y): + self.y = y + def get_plant(self): + return self.plant + def set_plant(self, plant): + self.plant = plant + def get_soil(self): + return self.soil + def set_soil(self, soil): + self.soil = soil \ No newline at end of file diff --git a/plant.py b/plant.py new file mode 100644 index 0000000..9189a1e --- /dev/null +++ b/plant.py @@ -0,0 +1,27 @@ +class Plant: + def __init__(self, name, organic, required_productivity, required_water_level, state): + self.name = name + self.organic = organic + self.required_productivity = required_productivity + self.required_water_level = required_water_level + self.state = state + def get_name(self): + return self.name + def set_name(self, name): + self.name = name + def get_organic(self): + return self.organic + def set_organic(self, organic): + self.organic = organic + def get_required_productivity(self): + return self.required_productivity + def set_required_productivity(self, required_productivity): + self.required_productivity = required_productivity + def get_required_water_level(self): + return self.required_water_level + def set_required_water_level(self, required_water_level): + self.required_water_level = required_water_level + def get_state(self): + return self.state + def set_state(self, state): + self.state = state \ No newline at end of file diff --git a/py.py b/py.py index e6f5f04..8b3dd77 100644 --- a/py.py +++ b/py.py @@ -1,39 +1,47 @@ -import os +import definitions +import field +import plant import pygame -WIDTH, HEIGHT = 1000, 1000 -WIN = pygame.display.set_mode((WIDTH, HEIGHT)) +import random +import soil +import tractor pygame.display.set_caption("Smart Tractor") -WHITE = ((255, 255, 255)) -FPS = 13 -TRACTOR_WIDTH, TRACTOR_HEIGHT = 100, 100 -TRACTOR = pygame.image.load(os.path.join('resources', 'tractor.png')) -TRACTOR = pygame.transform.scale(TRACTOR, (TRACTOR_WIDTH, TRACTOR_HEIGHT)) -VEL = 100 -def draw_window(tractor_rectangle): - WIN.fill(WHITE) - WIN.blit(TRACTOR, (tractor_rectangle.x, tractor_rectangle.y)) +def draw_window(tractor1_rectangle): + definitions.WIN.fill(definitions.WHITE) + definitions.WIN.blit(definitions.TRACTOR, (tractor1_rectangle.x, tractor1_rectangle.y)) pygame.display.update() -def tractor_handle_movement(keys_pressed, tractor_rectangle): - if keys_pressed[pygame.K_DOWN] and tractor_rectangle.y + VEL + TRACTOR_HEIGHT <= HEIGHT: - tractor_rectangle.y += VEL - if keys_pressed[pygame.K_LEFT] and tractor_rectangle.x - VEL >= 0: - tractor_rectangle.x -= VEL - if keys_pressed[pygame.K_RIGHT] and tractor_rectangle.x + VEL + TRACTOR_WIDTH <= WIDTH: - tractor_rectangle.x += VEL - if keys_pressed[pygame.K_UP] and tractor_rectangle.y - VEL >= 0: - tractor_rectangle.y -= VEL +def is_move_allowed(move, tractor1_rectangle): + return True +def tractor1_handle_movement(tractor1, tractor1_rectangle): + random1 = random.randint(1, 4) + if (random == 1 and is_move_allowed(1, tractor1_rectangle) == True): + tractor1.move_down() + tractor1_rectangle.x = tractor1.get_x() + tractor1_rectangle.y = tractor1.get_y() + elif (random == 2 and is_move_allowed(2, tractor1_rectangle) == True): + tractor1.move_left() + tractor1_rectangle.x = tractor1.get_x() + tractor1_rectangle.y = tractor1.get_y() + elif (random == 3 and is_move_allowed(3, tractor1_rectangle) == True): + tractor1.move_right() + tractor1_rectangle.x = tractor1.get_x() + tractor1_rectangle.y = tractor1.get_y() + elif (random == 4 and is_move_allowed(4, tractor1_rectangle) == True): + tractor1.move_up() + tractor1_rectangle.x = tractor1.get_x() + tractor1_rectangle.y = tractor1.get_y() def main(): - tractor_rectangle = pygame.Rect(0, 0, TRACTOR_WIDTH, TRACTOR_HEIGHT) + tractor1 = tractor.Tractor(0, 0) + tractor1_rectangle = pygame.Rect(tractor1.get_x(), tractor1.get_y(), definitions.TRACTOR_WIDTH, definitions.TRACTOR_HEIGHT) clock = pygame.time.Clock() run = True while run: - clock.tick(FPS) + clock.tick(definitions.FPS) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False - keys_pressed = pygame.key.get_pressed() - tractor_handle_movement(keys_pressed, tractor_rectangle) - draw_window(tractor_rectangle) + tractor1_handle_movement(tractor1, tractor1_rectangle) + draw_window(tractor1_rectangle) pygame.quit() if __name__ == "__main__": main() \ No newline at end of file diff --git a/soil.py b/soil.py new file mode 100644 index 0000000..3f47b52 --- /dev/null +++ b/soil.py @@ -0,0 +1,17 @@ +class Soil: + def __init__(self, name, state, water_level): + self.name = name + self.state = state + self.water_level = water_level + def get_name(self): + return self.name + def set_name(self, name): + self.name = name + def get_state(self): + return self.state + def set_state(self, state): + self.state = state + def get_water_level(self): + return self.water_level + def set_required_water_level(self, water_level): + self.water_level = water_level \ No newline at end of file diff --git a/tractor.py b/tractor.py new file mode 100644 index 0000000..aac5db9 --- /dev/null +++ b/tractor.py @@ -0,0 +1,21 @@ +import definitions +class Tractor: + def __init__(self, x, y): + self.x = x = 0 + self.y = y = 0 + def get_x(self): + return self.x + def set_x(self, x): + self.x = x + def get_y(self): + return self.y + def set_y(self, y): + self.y = y + def move_down(self): + self.y = self.y + definitions.VEL + def move_left(self): + self.x = self.x - definitions.VEL + def move_right(self): + self.x = self.x + definitions.VEL + def move_up(self): + self.y = self.y - definitions.VEL \ No newline at end of file