def __post_init__(self):
     super().__post_init__()
     if self.velocity < 0:
         raise NegativeParameterError(
             "Engine must have velocity of positive engine", self.velocity)
     if self.efficiency < 0.1 or self.efficiency > 1:
         raise NegativeParameterError(
             "Engine must have efficiency from 0.1 to 1", self.efficiency)
 def __post_init__(self):
     if self.missiles < 0:
         raise NegativeParameterError("Cannot have negative missile amount",
                                      self.missiles)
     if self.gun_ammo < 0:
         raise NegativeParameterError("Gun rounds cannot be negative",
                                      self.gun_ammo)
     if self.flares < 0:
         raise NegativeParameterError("Flares amount must be positive",
                                      self.flares)
 def __post_init__(self):
     super().__post_init__()
     if self.wheel_drive not in ['full', 'front', 'rear']:
         raise WheelDriveTypeError(self.wheel_drive)
     if self.max_ratio < 0:
         raise NegativeParameterError(
             "Engine must have rpm of positive engine", self.max_ratio)
Exemple #4
0
 def max_carry(self, val):
     if val < 0:
         raise NegativeParameterError("Carrying amount cannot be negative",
                                      val)
     if val > 2:
         raise ValueError(
             f"Fighter cannot carry more than 2 pilots, got {val}")
     self._max_carry = val
Exemple #5
0
 def weight(self, val):
     if val < 0:
         raise NegativeParameterError("Weight cannot be negative", val)
     if val > 3 * self._max_carry:
         print(
             f"Plane cannot weight more than 500 * carry_cap ({500 * self._max_carry}). Setting max weight"
         )
         self._weight = 3 * self._max_carry
     self._weight = val
Exemple #6
0
 def fight(self, enemies):
     if enemies < 0:
         raise NegativeParameterError(
             "Amount of enemies cannot be negative", enemies)
     if enemies == 0:
         print("Clear skies. No enemies, continue patrol")
         return True
     if self._weapons.fight(enemies):
         return True
     return False
Exemple #7
0
 def load(self, amount):
     if amount < 0:
         raise NegativeParameterError("Cannot load with negative weight",
                                      amount)
     if self._carrying + amount > self._max_carry:
         print(
             f"Unable to load {amount}. Carry limit of {self._max_carry} reached. Current load {self._carrying}"
         )
         return
     self._carrying += amount
     return self._carrying
Exemple #8
0
 def unload(self, amount):
     if amount < 0:
         raise NegativeParameterError(
             "Cannot remove negative weight from Car", amount)
     if self._carrying - amount < 0:
         print(
             f"Unable to unload {amount}. Car does not have such cargo. Removing all existing cargo"
         )
         self._carrying = 0
         return self._carrying
     self._carrying -= amount
     return self._carrying
Exemple #9
0
 def add_passengers(self, amount):
     if amount < 0:
         raise NegativeParameterError("Cannot get negative amount on board",
                                      amount)
     if self._carrying + amount > self._max_carry:
         print(
             f"Unable to load {amount} passengers. Plane carry limit of {self._max_carry} reached. Current load {self._carrying}"
         )
         return
     self._carrying += amount
     print(
         f"Loaded {amount} passengers to plane. Current cap {self._carrying} of {self._max_carry}"
     )
     return self._carrying
Exemple #10
0
 def rm_passengers(self, amount):
     if amount < 0:
         raise NegativeParameterError(
             "Cannot remove negative amount of people from board", amount)
     if self._carrying - amount < 0:
         print(
             f"Unable to rm {amount}. There are not enough on board. Removing all passengers"
         )
         self._carrying = 0
         return self._carrying
     self._carrying -= amount
     print(
         f"Removed {amount} passengers from plane. Current cap {self._carrying} of {self._max_carry}"
     )
     return self._carrying
Exemple #11
0
 def refuel(self, amount=0):
     if amount < 0:
         raise NegativeParameterError(
             "Cannot fuel with negative amount of petrol", amount)
     new_fuel = self._petrol + amount
     if new_fuel > self._fuel_capacity:
         print(
             f"Fueled full tank of {self._fuel_capacity}l, extra petrol {new_fuel - self._fuel_capacity}l is lost"
         )
         self._petrol = self._fuel_capacity
         return self._petrol
     print(
         f"Fueled car with {amount} litres, Now have {self._petrol + amount} litres"
     )
     self._petrol += amount
     return self._petrol
Exemple #12
0
 def __init__(self,
              weight=1000,
              carrying=0,
              max_carry=400,
              petrol=50,
              fuel_capacity=50,
              engine=Engine(90)):
     if weight < 0:
         raise NegativeParameterError("Weight cannot be negative", weight)
     self._weight = weight
     self._carrying = carrying
     self._max_carry = max_carry
     self._petrol = petrol
     self._fuel_capacity = fuel_capacity
     if not isinstance(engine, Engine):
         raise TypeError("Car must be init with proper Engine instance")
     self._engine = engine
Exemple #13
0
class Plane(Vehicle):
    def __init__(self,
                 weight=10000,
                 carrying=0,
                 max_carry=4000,
                 kerosene=500,
                 fuel_capacity=700,
                 engine=AvionicEngine(800, 9_000, 0.6)):
        if weight < 0:
            raise NegativeParameterError("Weight cannot be negative", weight)
        self._weight = weight
        self._carrying = carrying
        self._max_carry = max_carry
        self._kerosene = kerosene
        self._fuel_capacity = fuel_capacity
        if not isinstance(engine, AvionicEngine):
            raise TypeError(
                "Plane must be init with proper AvionicEngine instance")
        self._engine = engine
Exemple #14
0
 def __post_init__(self):
     if self.horses < 0:
         raise NegativeParameterError(
             "Engine cannot have negative horsepower", self.horses)
Exemple #15
0
 def carrying(self, val):
     if val < 0:
         raise NegativeParameterError("Carrying amount cannot be negative",
                                      val)
     self._carrying = val
Exemple #16
0
 def weight(self, val):
     if val < 0:
         raise NegativeParameterError("Weight cannot be negative", val)
     self._weight = val