Commit of the field board

This commit is contained in:
s481808 2024-03-07 18:01:12 +01:00
commit 56ae2c85de
24 changed files with 209 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

8
.idea/Traktor AI.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

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>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Traktor AI.iml" filepath="$PROJECT_DIR$/.idea/Traktor AI.iml" />
</modules>
</component>
</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>

3
source/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

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

4
source/.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>

8
source/.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/source.iml" filepath="$PROJECT_DIR$/.idea/source.iml" />
</modules>
</component>
</project>

8
source/.idea/source.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
source/.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$/../../TraktorRepositoryGit" vcs="Git" />
</component>
</project>

0
source/__init__.py Normal file
View File

0
source/area/__init__.py Normal file
View File

17
source/area/constants.py Normal file
View File

@ -0,0 +1,17 @@
# contains all constants
import pygame
WIDTH, HEIGHT = 1000, 1000
FIELD_WIDTH, FIELD_HEIGHT = 660, 330
ROWS, COLS = 10, 5
# number of tiles in a row and column
TILE_SIZE = FIELD_WIDTH//ROWS
PLANT = ""
# path to plant image
GROUND = ""
# path to ground image
GREY = (20, 17, 17, 255)

45
source/area/field.py Normal file
View File

@ -0,0 +1,45 @@
# create a field here : 1: add tiles, 2: place them
import pygame
from area.constants import WIDTH,HEIGHT,FIELD_WIDTH,FIELD_HEIGHT,TILE_SIZE,GREY,ROWS,COLS
from area.tractor import Tractor
from tile import Tile
tiles = []
tractor = Tractor(0*TILE_SIZE, 0*TILE_SIZE)
fieldX = (WIDTH-FIELD_WIDTH)/2
# in center of the screen
fieldY = 100
# move field elements to field position
def positionFieldElements():
for t in tiles:
t.x += fieldX
t.y += fieldY
tractor.x += fieldX
tractor.y += fieldY
def createTiles():
for y in range (0,COLS):
for x in range (0,ROWS):
tile = Tile(x*TILE_SIZE, y*TILE_SIZE)
tile.randomizeContent()
tiles.append(tile)
positionFieldElements()
def createField(win):
createTiles()
for t in tiles:
image = pygame.image.load(t.image).convert()
image = pygame.transform.scale(image, (TILE_SIZE, TILE_SIZE))
win.blit(image, (t.x, t.y))
pygame.display.flip()
imageTractor = pygame.image.load(tractor.image).convert_alpha()
imageTractor = pygame.transform.scale(imageTractor, (TILE_SIZE, TILE_SIZE))
win.blit(imageTractor, (tractor.x, tractor.y))
pygame.display.flip()
def drawWindow(win):
win.fill(GREY)
createField(win)

9
source/area/tractor.py Normal file
View File

@ -0,0 +1,9 @@
class Tractor:
x = None
y = None
image = None
# etc
def __init__(self,x,y):
self.x = x
self.y = y
self.image = 'resources/images/tractor.png'

6
source/ground.py Normal file
View File

@ -0,0 +1,6 @@
class Dirt:
state = None
# add a couple new properties
# add init, getters,setters

20
source/main.py Normal file
View File

@ -0,0 +1,20 @@
import pygame
from area.constants import WIDTH, HEIGHT
from area.field import drawWindow
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Intelligent tractor')
def main():
run = True
window = drawWindow(WIN)
pygame.display.update()
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# in loop move tractor
main()

8
source/plant.py Normal file
View File

@ -0,0 +1,8 @@
class Plant:
name = None
# more properties
# add init, getters,setters

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

34
source/tile.py Normal file
View File

@ -0,0 +1,34 @@
import random
class Tile:
x = 0
y = 0
plant = None
ground = None
photo = None
image = None
# after checking a photo add information plant object ("potato"/ "wheat"/"none")
# add Ground instance
def __init__(self, x, y):
self.x = x
self.y = y
# add to init ground instance
# called on a created tile
def randomizeContent(self):
i = random.randint(1, 3) #szansa 1/3
if i == 1:
self.image = "resources/images/sampling.png"
#self.picture losuje dodatkowo zdjecie jakies rosliny do danego rzędu
else:
self.image = "resources/images/dirt.png"
# DISCLAMER check column and choose plant type ("potato","wheat" etc)