testowanie ruchu

This commit is contained in:
Tomasz Adamczyk 2021-03-21 12:40:13 +01:00
parent 2c1ff6c64c
commit 5100e3e060
13 changed files with 189 additions and 36 deletions

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="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,13 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" name="Default Changelist" comment="" />
<list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/py.py" beforeDir="false" afterPath="$PROJECT_DIR$/py.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_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectId" id="1pifVLVEDyFxW85jvOgQt0TyQ4g" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" />
@ -16,6 +30,12 @@
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.tslint" value="true" />
<property name="node.js.path.for.package.eslint" value="project" />
<property name="node.js.path.for.package.tslint" value="project" />
<property name="node.js.selected.package.eslint" value="(autodetect)" />
<property name="node.js.selected.package.tslint" value="(autodetect)" />
</component>
<component name="RunManager">
<configuration name="py" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
@ -57,6 +77,8 @@
<option name="presentableId" value="Default" />
<updated>1615670853142</updated>
<workItem from="1615670854240" duration="68000" />
<workItem from="1616276134469" duration="1463000" />
<workItem from="1616322081205" duration="4362000" />
</task>
<servers />
</component>
@ -64,24 +86,44 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1615670921889">
<state width="1879" height="364" key="GridCell.Tab.0.bottom" timestamp="1616326478875">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1615670921889" />
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1615670921889">
<state width="1879" height="364" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1616326478875" />
<state width="1879" height="364" key="GridCell.Tab.0.center" timestamp="1616326478875">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1615670921889" />
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1615670921889">
<state width="1879" height="364" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1616326478875" />
<state width="1879" height="364" key="GridCell.Tab.0.left" timestamp="1616326478875">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1615670921889" />
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1615670921889">
<state width="1879" height="364" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1616326478875" />
<state width="1879" height="364" key="GridCell.Tab.0.right" timestamp="1616326478875">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1615670921889" />
<state width="1879" height="364" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1616326478875" />
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1616326478876">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="364" key="GridCell.Tab.1.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1616326478876" />
<state width="1879" height="364" key="GridCell.Tab.1.center" timestamp="1616326478875">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="364" key="GridCell.Tab.1.center/0.0.1920.1080@0.0.1920.1080" timestamp="1616326478875" />
<state width="1879" height="364" key="GridCell.Tab.1.left" timestamp="1616326478875">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="364" key="GridCell.Tab.1.left/0.0.1920.1080@0.0.1920.1080" timestamp="1616326478875" />
<state width="1879" height="364" key="GridCell.Tab.1.right" timestamp="1616326478875">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1616326478875" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1616322080552">
<screen x="0" y="0" width="1920" height="1080" />
</state>
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1616322080552" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1615670883139" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1616326392782" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

10
definitions.py Normal file
View File

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

22
field.py Normal file
View File

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

27
plant.py Normal file
View File

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

60
py.py
View File

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

17
soil.py Normal file
View File

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

21
tractor.py Normal file
View File

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