Advertisement
Nenogzar

1

Aug 11th, 2024
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. from abc import ABC, abstractmethod
  2.  
  3.  
  4. class BaseEquipment(ABC):
  5.     equipment_properties = {
  6.         'ElbowPad': {'PROTECTION': 90, 'PRICE': 25.0, 'INCREASES_PRICE': 1.1},
  7.         'KneePad': {'PROTECTION': 120, 'PRICE': 15.0, 'INCREASES_PRICE': 1.2}
  8.     }
  9.  
  10.     def __init__(self, protection: int = None, price: float = None):
  11.         self.protection = protection
  12.         self.price = price
  13.         self.class_name = self.__class__.__name__
  14.  
  15.         #
  16.         # self._protection = self.equipment_properties[class_name]['PROTECTION']
  17.         # self._price = self.equipment_properties[class_name]['PRICE']
  18.  
  19.      
  20.     @property
  21.     def protection(self):
  22.         return self._protection
  23.        
  24.    
  25.     @protection.setter
  26.     def protection(self):
  27.         self._protection = self.equipment_properties[self.class_name]['PROTECTION']
  28.    
  29.     @property
  30.     def price(self):
  31.         return self._price
  32.    
  33.     @price.setter
  34.     def price(self):
  35.         self._price = self.equipment_properties[self.class_name]['PRICE']
  36.        
  37.     def increase_price(self) -> None:
  38.         class_name = self.__class__.__name__
  39.         increase_factor = self.equipment_properties[class_name]['INCREASES_PRICE']
  40.         self._price *= increase_factor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement