From b2adadaac73461060b277add7e7d5cad346e7651 Mon Sep 17 00:00:00 2001 From: Bondzik-S Date: Tue, 8 Oct 2024 15:26:17 +0300 Subject: [PATCH] Solution --- app/main.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 52a3e644..b1362fc1 100644 --- a/app/main.py +++ b/app/main.py @@ -2,4 +2,75 @@ class Cargo: def __init__(self, weight: int) -> None: self.weight = weight -# write your code here + +class BaseRobot: + def __init__( + self, + name: str, + weight: int, + coords: list = None + ) -> None: + self.name = name + self.weight = weight + self.coords = coords or [0, 0] + + def go_forward(self, step: int = 1) -> list: + self.coords[1] += step + return self.coords + + def go_back(self, step: int = 1) -> list: + self.coords[1] -= step + return self.coords + + def go_right(self, step: int = 1) -> list: + self.coords[0] += step + return self.coords + + def go_left(self, step: int = 1) -> list: + self.coords[0] -= step + return self.coords + + def get_info(self) -> str: + return f"Robot: {self.name}, Weight: {self.weight}" + + +class FlyingRobot(BaseRobot): + def __init__( + self, + name: str, + weight: int, + coords: list = None + ) -> None: + super().__init__(name, weight, coords) + self.coords = coords or [0, 0, 0] + + def go_up(self, step: int = 1) -> list: + self.coords[2] += step + return self.coords + + def go_down(self, step: int = 1) -> list: + self.coords[2] -= step + return self.coords + + +class DeliveryDrone(FlyingRobot): + def __init__( + self, + name: str, + weight: int, + max_load_weight: int, + current_load: Cargo, + coords: list = None + ) -> None: + super().__init__(name, weight, coords) + self.coords = coords or [0, 0, 0] + self.max_load_weight = max_load_weight + self.current_load = current_load + + def hook_load(self, cargo_obj: Cargo) -> None: + if (self.current_load is None + and cargo_obj.weight <= self.max_load_weight): + self.current_load = cargo_obj + + def unhook_load(self) -> None: + self.current_load = None