Refactor unit classes to reduce code duplication and improve maintainability
- Updated the Unit base class to include common attributes and methods for all units. - Refactored Bomb, Point, and Rat classes to inherit from the new Unit class structure. - Implemented a consistent die method across units for better cleanup. - Removed redundant code in unit initialization and added specific attributes where necessary. - Deleted obsolete configuration file and added a comprehensive architecture guide for future reference.
This commit is contained in:
+7
-13
@@ -8,16 +8,9 @@ AGE_THRESHOLD = 200
|
||||
|
||||
class Point(Unit):
|
||||
def __init__(self, game, position=(0,0), id=None, value=5):
|
||||
super().__init__(position)
|
||||
self.id = id if id else uuid.uuid4()
|
||||
self.game = game
|
||||
self.position = position
|
||||
self.bbox = (0, 0, 0, 0)
|
||||
self.stop = 0
|
||||
self.age = 0
|
||||
self.speed = 4
|
||||
self.partial_move = 0
|
||||
self.position_before = position
|
||||
super().__init__(game, position, id)
|
||||
# Specific attributes for points
|
||||
self.speed = 4 # Points age faster
|
||||
self.fight = False
|
||||
self.value = value
|
||||
self.game.add_point(self.value)
|
||||
@@ -31,9 +24,10 @@ class Point(Unit):
|
||||
pass
|
||||
|
||||
def die(self, unit=None, score=None):
|
||||
if not unit:
|
||||
unit = self
|
||||
self.game.units.pop(unit.id)
|
||||
"""Handle point cleanup. Points just disappear when they expire."""
|
||||
target_unit = unit if unit else self
|
||||
# Use base class cleanup
|
||||
super().die()
|
||||
|
||||
|
||||
def draw(self):
|
||||
|
||||
Reference in New Issue
Block a user