lllumineux

Untitled

Nov 30th, 2020
704
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Element:
  2.     def __str__(self):
  3.         return self.__class__.__name__
  4.  
  5.     def __add__(self, other):
  6.         key = type(self), type(other)
  7.         if key in TRANSFORMATIONS_TABLE:
  8.             return TRANSFORMATIONS_TABLE[key]()
  9.  
  10.         key = type(other), type(self)
  11.         if key in TRANSFORMATIONS_TABLE:
  12.             return TRANSFORMATIONS_TABLE[key]()
  13.  
  14.  
  15. class Water(Element):
  16.     pass
  17.  
  18.  
  19. class Air(Element):
  20.     pass
  21.  
  22.  
  23. class Fire(Element):
  24.     pass
  25.  
  26.  
  27. class Dirt(Element):
  28.     pass
  29.  
  30.  
  31. class Storm(Element):
  32.     pass
  33.  
  34.  
  35. class Vapor(Element):
  36.     pass
  37.  
  38.  
  39. class Mud(Element):
  40.     pass
  41.  
  42.  
  43. class Lightning(Element):
  44.     pass
  45.  
  46.  
  47. class Dust(Element):
  48.     pass
  49.  
  50.  
  51. class Lava(Element):
  52.     pass
  53.  
  54.  
  55. TRANSFORMATIONS_TABLE = {
  56.     (Water, Air): Storm,
  57.     (Water, Fire): Vapor,
  58.     (Water, Dirt): Mud,
  59.     (Air, Fire): Lightning,
  60.     (Air, Dirt): Dust,
  61.     (Fire, Dirt): Lava,
  62. }
  63.  
  64. print(f"{Water()} + {Air()} = {Water() + Air()}")
  65. print(f"{Water()} + {Fire()} = {Water() + Fire()}")
  66. print(f"{Water()} + {Dirt()} = {Water() + Dirt()}")
  67. print(f"{Air()} + {Fire()} = {Air() + Fire()}")
  68. print(f"{Air()} + {Dirt()} = {Air() + Fire()}")
  69. print(f"{Fire()} + {Dirt()} = {Fire() + Dirt()}")
  70.  
RAW Paste Data