diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Machine_learning_2023.iml b/.idea/Machine_learning_2023.iml new file mode 100644 index 0000000..f6175b4 --- /dev/null +++ b/.idea/Machine_learning_2023.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c69c90c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..5e0b360 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file 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/domain/commands/vacuum_move_command.py b/domain/commands/vacuum_move_command.py index b868e33..d150c2a 100644 --- a/domain/commands/vacuum_move_command.py +++ b/domain/commands/vacuum_move_command.py @@ -30,5 +30,13 @@ class VacuumMoveCommand(Command): if self.world.is_obstacle_at(end_x, end_y): return + if self.world.is_garbage_at(end_x, end_y): + if self.vacuum.get_container_filling() < 100: + self.vacuum.increase_container_filling() + self.world.dust[end_x][end_y].pop() + + if self.world.is_docking_station_at(end_x, end_y): + self.vacuum.dump_trash() + self.vacuum.x = end_x self.vacuum.y = end_y diff --git a/domain/entities/docking_station.py b/domain/entities/docking_station.py new file mode 100644 index 0000000..34262a7 --- /dev/null +++ b/domain/entities/docking_station.py @@ -0,0 +1,10 @@ +from domain.entities.entity import Entity +from domain.world import World + + +class Doc_Station(Entity): + def __init__(self, x: int, y: int): + super().__init__(x, y, "DOC_STATION") + self.power = True + + # TODO Docing Station: add more properties \ No newline at end of file diff --git a/domain/entities/vacuum.py b/domain/entities/vacuum.py index 03fa7d8..1ccbc14 100644 --- a/domain/entities/vacuum.py +++ b/domain/entities/vacuum.py @@ -9,4 +9,13 @@ class Vacuum(Entity): self.cleaning_detergent = 100 self.container_filling = 0 - # TODO VACUUM: add more properties + def increase_container_filling(self) -> None: + self.container_filling += 25 + + def dump_trash(self) -> None: + self.container_filling = 0 + + def get_container_filling(self): + return self.container_filling + + # TODO VACUUM: add more properties diff --git a/domain/world.py b/domain/world.py index e6d10b5..d2b3f02 100644 --- a/domain/world.py +++ b/domain/world.py @@ -2,7 +2,7 @@ from domain.entities.entity import Entity class World: - def __init__(self, width: int, height: int): + def __init__(self, width: int, height: int) -> object: self.width = width self.height = height self.dust = [[[] for j in range(height)] for i in range(width)] @@ -10,12 +10,15 @@ class World: self.vacuum = None self.cat = None + self.doc_station = None def add_entity(self, entity: Entity): if entity.type == "PEEL": self.dust[entity.x][entity.y].append(entity) elif entity.type == "VACUUM": self.vacuum = entity + elif entity.type == "DOC_STATION": + self.doc_station = entity elif entity.type == "CAT": self.cat = entity self.obstacles[entity.x][entity.y].append(entity) @@ -24,3 +27,9 @@ class World: def is_obstacle_at(self, x: int, y: int) -> bool: return bool(self.obstacles[x][y]) + + def is_garbage_at(self, x: int, y: int) -> bool: + return bool(self.dust[x][y]) + + def is_docking_station_at(self, x: int, y: int) -> bool: + return bool(self.doc_station.x == x and self.doc_station.y == y) diff --git a/main.py b/main.py index 52690b9..2dac579 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ from domain.commands.vacuum_move_command import VacuumMoveCommand from domain.entities.cat import Cat from domain.entities.entity import Entity from domain.entities.vacuum import Vacuum +from domain.entities.docking_station import Doc_Station from domain.world import World from view.renderer import Renderer @@ -62,7 +63,6 @@ class Main: def update(self): self.commands.append(RandomCatMoveCommand(self.world, self.world.cat)) - for command in self.commands: command.run() self.commands.clear() @@ -75,6 +75,7 @@ def generate_world(tiles_x: int, tiles_y: int) -> World: temp_y = randint(0, tiles_y - 1) world.add_entity(Entity(temp_x, temp_y, "PEEL")) world.vacuum = Vacuum(1, 1) + world.doc_station = Doc_Station(9, 8) world.cat = Cat(7, 8) world.add_entity(world.cat) world.add_entity(Entity(2, 8, "PLANT1")) diff --git a/media/sprites/docking_station.png b/media/sprites/docking_station.png new file mode 100644 index 0000000..c7c0d71 Binary files /dev/null and b/media/sprites/docking_station.png differ diff --git a/view/renderer.py b/view/renderer.py index bfe1dde..ab3d8de 100644 --- a/view/renderer.py +++ b/view/renderer.py @@ -31,10 +31,13 @@ class Renderer: pygame.display.set_caption("AI Vacuum Cleaner") self.screen = pygame.display.set_mode((self.width, self.height)) + self.font = pygame.font.SysFont('Arial', 26, bold=True) self.sprites = { "VACUUM": pygame.transform.scale(pygame.image.load("media/sprites/vacuum.png"), (self.tile_width, self.tile_height)), + "DOC_STATION": pygame.transform.scale(pygame.image.load("media/sprites/docking_station.png"), + (self.tile_width, self.tile_height)), "WALL": pygame.transform.scale(pygame.image.load("media/sprites/wall.png"), (self.tile_width, self.tile_height)), "TILE": pygame.transform.scale(pygame.image.load("media/sprites/tile_cropped.jpeg"), @@ -76,6 +79,7 @@ class Renderer: for entity in world.obstacles[x][y]: self.draw_entity(entity) self.draw_entity(world.vacuum) + self.draw_entity(world.doc_station) self.draw_entity(world.cat) pygame.display.update() @@ -92,10 +96,19 @@ class Renderer: def draw_entity(self, entity: Entity): sprite = self.sprites.get(entity.type, None) draw_pos = (entity.x * self.tile_width, entity.y * self.tile_height) + if "PEEL" in entity.type: + draw_pos = ((entity.x - 0.1) * self.tile_width, (entity.y - 0.25) * self.tile_height) if "PLANT" in entity.type: draw_pos = ((entity.x - 0.1) * self.tile_width, (entity.y - 0.25) * self.tile_height) if "CAT" in entity.type and isinstance(entity, Cat): sprite = self.cat_direction_sprite[entity.direction] + if "VACUUM" in entity.type: + # Add text displaying container filling level + text_surface = self.font.render(f"Filling: {entity.container_filling}%", True, Color("black")) + text_pos = (draw_pos[0] + self.tile_width / 2 - text_surface.get_width() / 2, draw_pos[1] + self.tile_height) + self.screen.blit(text_surface, text_pos) + if "DOC_STATION" in entity.type: + draw_pos = ((entity.x - 0.1) * self.tile_width, (entity.y - 0.25) * self.tile_height) self.screen.blit(sprite, draw_pos) def draw_sprite(self, x: int, y: int, sprite_name: str): @@ -110,4 +123,4 @@ class Renderer: self.draw_sprite(tile_x, tile_y, sprite) def render_floor(self): - self.fill_grid_with_sprite("TILE") + self.fill_grid_with_sprite("TILE") \ No newline at end of file