|
|
@@ -78,7 +78,51 @@ class RandomGroup(Group):
|
|
|
super().__init__(characters_list)
|
|
|
|
|
|
|
|
|
-class SquareGroup(Group):
|
|
|
+class RectangleGroup(Group):
|
|
|
+ """
|
|
|
+ Group of characters forming a rectangle.
|
|
|
+
|
|
|
+ Examples:
|
|
|
+ >>> ch = Character('protagonist.png')
|
|
|
+ >>> rg = RectangleGroup(ch, 5, 3)
|
|
|
+ """
|
|
|
+
|
|
|
+ def __init__(self, model: Type['Character'], base: int, height: int):
|
|
|
+ # TODO: check model type
|
|
|
+ if not isinstance(base, int) or not isinstance(height, int):
|
|
|
+ raise TypeError(_('Both the base and rectangle must be integers.'))
|
|
|
+ if base < 1 or height < 1:
|
|
|
+ raise ValueError(
|
|
|
+ _('Both the base and rectangle must be positive.')
|
|
|
+ )
|
|
|
+ if base == 1 and height == 1:
|
|
|
+ raise ValueError(
|
|
|
+ _(
|
|
|
+ 'At least one of the dimensions of the rectangle must be greater than 1.'
|
|
|
+ )
|
|
|
+ )
|
|
|
+ self.base = base
|
|
|
+ self.height = height
|
|
|
+ self.amount = base * height
|
|
|
+
|
|
|
+ characters_list = []
|
|
|
+ for row in range(self.height):
|
|
|
+ for col in range(self.base):
|
|
|
+ if not characters_list:
|
|
|
+ new_character = model
|
|
|
+ else:
|
|
|
+ new_character = model.copy()
|
|
|
+ new_character.set_position(
|
|
|
+ (
|
|
|
+ model.x + model.width * col,
|
|
|
+ model.y + model.height * row,
|
|
|
+ )
|
|
|
+ )
|
|
|
+ characters_list.append(new_character)
|
|
|
+ super().__init__(characters_list)
|
|
|
+
|
|
|
+
|
|
|
+class SquareGroup(RectangleGroup):
|
|
|
"""
|
|
|
Group of characters forming a square.
|
|
|
|
|
|
@@ -96,20 +140,7 @@ class SquareGroup(Group):
|
|
|
_('The side of the square must be greater than 1.')
|
|
|
)
|
|
|
self.side = side
|
|
|
- self.amount = side**2
|
|
|
-
|
|
|
- characters_list = []
|
|
|
- for pos in range(self.amount):
|
|
|
- new_character = model.copy()
|
|
|
- new_character.set_position(
|
|
|
- (
|
|
|
- model.width * (pos // self.side),
|
|
|
- model.height * (pos % self.side),
|
|
|
- )
|
|
|
- )
|
|
|
- characters_list.append(new_character)
|
|
|
-
|
|
|
- super().__init__(characters_list)
|
|
|
+ super().__init__(model, side, side)
|
|
|
|
|
|
|
|
|
class StairsGroup(Group):
|