feat(game): add __mult__ and __imult__ methods for Direction

Returns tuple of values that were multiplied by a constant
This commit is contained in:
Kristofers Solo 2023-12-29 16:56:28 +02:00
parent cad0e87663
commit 79c3bee2a3

8
src/py2048/utils.py Normal file → Executable file
View File

@ -6,3 +6,11 @@ class Direction(Enum):
DOWN = (0, 1)
LEFT = (-1, 0)
RIGHT = (1, 0)
def __mul__(self, num: int) -> tuple[int, int]:
"""Multiply the direction by a constant."""
return self.value[0] * num, self.value[1] * num
def __imul__(self, num: int) -> tuple[int, int]:
"""Multiply the direction by a constant."""
return self.value[0] * num, self.value[1] * num