mirror of
https://github.com/kristoferssolo/2048.git
synced 2025-10-21 15:20:35 +00:00
refactor(game): update dunder methods
This commit is contained in:
parent
56f32f7b4a
commit
848db04af2
@ -57,19 +57,15 @@ class Block(pygame.sprite.Sprite):
|
|||||||
}
|
}
|
||||||
self.image.fill(color_map.get(self.value, COLORS.ERROR))
|
self.image.fill(color_map.get(self.value, COLORS.ERROR))
|
||||||
|
|
||||||
def __add__(self, other: "Block") -> "Block":
|
def __add__(self, other: "Block") -> None:
|
||||||
"""Add the value of two blocks and return a new block"""
|
"""Add the value of two blocks and update the current block"""
|
||||||
new_block = Block(self.rect.x, self.rect.y)
|
self.value += other.value
|
||||||
new_block.value = self.value + other.value
|
self.update()
|
||||||
return new_block
|
|
||||||
|
|
||||||
def __iadd__(self, other: "Block") -> "Block":
|
def __iadd__(self, other: "Block") -> None:
|
||||||
"""Add the value of two blocks and return a new block"""
|
"""Add the value of two blocks and updae the current block"""
|
||||||
return self + other
|
self.value += other.value
|
||||||
|
self.update()
|
||||||
def __eq__(self, other: "Block") -> bool:
|
|
||||||
"""Check if two block values are equal"""
|
|
||||||
return self.value == other.value
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
"""Return a string representation of the block"""
|
"""Return a string representation of the block"""
|
||||||
@ -77,7 +73,7 @@ class Block(pygame.sprite.Sprite):
|
|||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
"""Return a string representation of the block"""
|
"""Return a string representation of the block"""
|
||||||
self.__repr__()
|
return self.__repr__()
|
||||||
|
|
||||||
def __hash__(self) -> int:
|
def __hash__(self) -> int:
|
||||||
"""Return a hash of the block"""
|
"""Return a hash of the block"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user