This commit is contained in:
s464923 2024-03-10 02:46:14 +01:00
commit 569d790144
19 changed files with 131 additions and 0 deletions

3
.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
.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 (traktor)" 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.iml" filepath="$PROJECT_DIR$/.idea/traktor.iml" />
</modules>
</component>
</project>

10
.idea/traktor.iml Normal file
View File

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

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>

Binary file not shown.

Binary file not shown.

Binary file not shown.

25
board.py Normal file
View File

@ -0,0 +1,25 @@
import pygame
from constant import size, rows, cols
class Board:
def __init__(self):
self.board = []
def load_images(self):
self.grass = pygame.image.load("grass.png")
self.dirt = pygame.image.load("dirt.png")
def draw_cubes(self, win):
for row in range(rows):
for col in range(cols):
cube_rect = pygame.Rect(row * size, col * size, size, size)
if (row + col) % 2 == 0:
win.blit(self.grass, cube_rect)
else:
win.blit(self.dirt, cube_rect)

7
constant.py Normal file
View File

@ -0,0 +1,7 @@
import pygame
width, height = 640, 640
rows, cols = 8, 8
size = width//cols
yellow = (216,178,0)
green= (103,178,0)
red = (255,0,0)

BIN
dirt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 699 KiB

BIN
down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
grass.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

BIN
left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

46
main.py Normal file
View File

@ -0,0 +1,46 @@
import pygame
from board import Board
from constant import width, height, rows, cols
from tractor import Tractor
fps = 5
WIN = pygame.display.set_mode((width, height))
pygame.display.set_caption('Inteligenty Traktor')
def main():
run = True
clock = pygame.time.Clock()
board = Board()
board.load_images()
tractor = Tractor(4, 4)
while run:
clock.tick(fps)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_UP] and tractor.row > 0:
tractor.row -= 1
tractor.direction = "up"
if keys[pygame.K_DOWN] and tractor.row < rows-1:
tractor.row += 1
tractor.direction = "down"
if keys[pygame.K_LEFT] and tractor.col > 0:
tractor.col -= 1
tractor.direction = "left"
if keys[pygame.K_RIGHT] and tractor.col < cols -1:
tractor.col += 1
tractor.direction = "right"
board.draw_cubes(WIN)
tractor.draw(WIN)
pygame.display.update()
pygame.quit()
main()

BIN
right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

16
tractor.py Normal file
View File

@ -0,0 +1,16 @@
import pygame
from constant import size
class Tractor:
def __init__(self, row, col):
self.row = row
self.col = col
self.images = {
"up": pygame.image.load("up.png"),
"down": pygame.image.load("down.png"),
"left":pygame.image.load("left.png"),
"right":pygame.image.load("right.png")
}
self.direction = "down"
def draw(self, win):
tractor_image = self.images[self.direction]
win.blit(tractor_image, (self.col*size, self.row*size))

BIN
up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB