added tile class, refactor some other classes
This commit is contained in:
parent
1d2610b23e
commit
7c31461da6
@ -5,7 +5,7 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (ai-project)" project-jdk-type="Python SDK" />
|
||||
</project>
|
27
main.py
27
main.py
@ -1,37 +1,40 @@
|
||||
import pygame
|
||||
|
||||
from src.world_creator import World
|
||||
from settings import Settings
|
||||
from src.world import World
|
||||
from src.tractor import Tractor
|
||||
from src.settings import Settings
|
||||
|
||||
|
||||
def draw_line(screen: pygame.display, tile_size, settings):
|
||||
def draw_line(screen: pygame.display, settings):
|
||||
for line in range(0, 11):
|
||||
pygame.draw.line(screen, (255, 255, 255), (0, line * tile_size), (settings.screen_width, line*tile_size))
|
||||
pygame.draw.line(screen, (255, 255, 255), (line * tile_size, 0), (line * tile_size, settings.screen_height))
|
||||
pygame.draw.line(screen, (255, 255, 255), (0, line * settings.tile_size),
|
||||
(settings.screen_width, line*settings.tile_size))
|
||||
pygame.draw.line(screen, (255, 255, 255), (line * settings.tile_size, 0),
|
||||
(line * settings.tile_size, settings.screen_height))
|
||||
|
||||
|
||||
# TODO: add Sprite to every class and store Tile objects as Sprite group
|
||||
|
||||
def main():
|
||||
print('siema')
|
||||
pygame.init()
|
||||
|
||||
settings = Settings()
|
||||
world = World(settings)
|
||||
tractor = Tractor("Spalinowy", "Nawóz 1", settings)
|
||||
|
||||
screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
|
||||
world = World(settings.screen_title_size)
|
||||
pygame.display.set_caption('TRAKTOHOLIK')
|
||||
|
||||
background_image = pygame.image.load('assets/images/sky.png')
|
||||
background_image = pygame.transform.scale(background_image, (settings.screen_width, settings.screen_height))
|
||||
tractor_image = pygame.transform.scale(pygame.image.load('assets/images/tractor.png'),
|
||||
(0.9*settings.screen_title_size, 0.9*settings.screen_title_size))
|
||||
|
||||
run = True
|
||||
|
||||
while run:
|
||||
|
||||
screen.blit(background_image, (0, 0))
|
||||
world.draw(screen)
|
||||
draw_line(screen, settings.screen_title_size, settings)
|
||||
screen.blit(tractor_image, (6*settings.screen_title_size, 5*settings.screen_title_size))
|
||||
draw_line(screen, settings)
|
||||
screen.blit(tractor.image, (6*settings.tile_size, 5*settings.tile_size))
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
|
@ -1,5 +1,5 @@
|
||||
class Plant:
|
||||
"""class representing plants"""
|
||||
""" Class representing plants """
|
||||
|
||||
def __init__(self, species, tile):
|
||||
self.species = species
|
||||
@ -29,8 +29,8 @@ class Plant:
|
||||
self.growth = 0 # value between 0 and 1
|
||||
self.wilted = False
|
||||
|
||||
def remove(self):
|
||||
self.tile.planted = False
|
||||
def remove(self): # to chyba do usunięcia, bo to tile zawiera planta, a nie na odwrót
|
||||
self.tile.plant = None
|
||||
|
||||
def grow(self):
|
||||
return True
|
||||
|
@ -1,8 +1,10 @@
|
||||
class Settings:
|
||||
""" A class to represent all settings for the game, maybe later as .cfg """
|
||||
""" Class to represent all settings for the app, maybe later as .cfg """
|
||||
|
||||
def __init__(self):
|
||||
# Screen settings
|
||||
self.screen_width = 1100
|
||||
self.screen_height = 1100
|
||||
self.screen_title_size = 110
|
||||
self.screen_width = 800
|
||||
self.screen_height = 800
|
||||
|
||||
# Tile settings
|
||||
self.tile_size = 80
|
||||
|
24
src/tile.py
Normal file
24
src/tile.py
Normal file
@ -0,0 +1,24 @@
|
||||
class Tile:
|
||||
""" Class to represent single board tile """
|
||||
|
||||
def __init__(self, row_id, col_id, image, rect):
|
||||
self.row_id = row_id
|
||||
self.col_id = col_id
|
||||
self.position = (row_id, col_id)
|
||||
self.image = image
|
||||
self.rect = rect
|
||||
self.plant = None
|
||||
self.hydration = 0
|
||||
self.fertilizer = None
|
||||
self.is_fertilized = False
|
||||
|
||||
def add_plant(self, plant):
|
||||
self.plant = plant
|
||||
|
||||
def remove_plant(self):
|
||||
self.plant = None
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,11 +1,14 @@
|
||||
import pygame
|
||||
|
||||
|
||||
class Tractor:
|
||||
""" A class to represent our agent """
|
||||
|
||||
def __init__(self, engine, addition, trajectory):
|
||||
""" Class to represent our agent """
|
||||
|
||||
def __init__(self, engine, fertilizer, settings):
|
||||
self.image = pygame.transform.scale(pygame.image.load('assets/images/tractor.png'),
|
||||
(0.9*settings.tile_size, 0.9*settings.tile_size))
|
||||
self.engine = engine
|
||||
self.addition = addition
|
||||
self.trajectory = trajectory
|
||||
self.fertilizer = fertilizer
|
||||
|
||||
def hydrate(self, tile):
|
||||
if tile.hydration < tile.plant.min_hydration:
|
||||
@ -18,11 +21,11 @@ class Tractor:
|
||||
def cut(self, tile):
|
||||
tile.remove_plant()
|
||||
|
||||
def plant(self, tile):
|
||||
if not tile.planted:
|
||||
tile.plant()
|
||||
def plant(self, tile, plant):
|
||||
if not tile.plant:
|
||||
tile.add_plant(plant)
|
||||
|
||||
def fertilize(self, tile):
|
||||
if not tile.isfertilized:
|
||||
tile.isFertilized = True
|
||||
if not tile.is_fertilized:
|
||||
tile.is_fertilized = True
|
||||
tile.fertilizer = tile.plant.fertilizer
|
||||
|
@ -1,8 +1,9 @@
|
||||
import pygame
|
||||
from src.tile import Tile
|
||||
|
||||
|
||||
class World:
|
||||
""" A class to represent game board """
|
||||
""" Class to represent complete game board """
|
||||
|
||||
world_data = [
|
||||
[1, 1, 1, 1, 0, 0, 1, 1, 1, 1],
|
||||
@ -17,27 +18,29 @@ class World:
|
||||
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
|
||||
] # it will be changed when miguel sends his code
|
||||
|
||||
def __init__(self, tile_size):
|
||||
def __init__(self, settings):
|
||||
self.tile_list = []
|
||||
self.dirt_image = pygame.image.load('assets/images/dirt.jpeg')
|
||||
self.gravel_image = pygame.image.load('assets/images/gravel.jpeg')
|
||||
self.settings = settings
|
||||
|
||||
row_count = 0
|
||||
for row in self.world_data:
|
||||
col_count = 0
|
||||
|
||||
for tile in row:
|
||||
if tile == 1:
|
||||
img = pygame.transform.scale(self.dirt_image, (tile_size, tile_size))
|
||||
img = pygame.transform.scale(self.dirt_image, (settings.tile_size, settings.tile_size))
|
||||
elif tile == 0:
|
||||
img = pygame.transform.scale(self.gravel_image, (tile_size, tile_size))
|
||||
img = pygame.transform.scale(self.gravel_image, (settings.tile_size, settings.tile_size))
|
||||
img_rect = img.get_rect()
|
||||
img_rect.x = col_count * tile_size
|
||||
img_rect.y = row_count * tile_size
|
||||
tile = (img, img_rect)
|
||||
img_rect.x = col_count * settings.tile_size
|
||||
img_rect.y = row_count * settings.tile_size
|
||||
tile = Tile(row_count, col_count, img, img_rect)
|
||||
self.tile_list.append(tile)
|
||||
col_count += 1
|
||||
row_count += 1
|
||||
|
||||
def draw(self, screen):
|
||||
for tile in self.tile_list:
|
||||
screen.blit(tile[0], tile[1])
|
||||
screen.blit(tile.image, tile.rect)
|
Loading…
Reference in New Issue
Block a user