Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit_configs = {
- "Knight": {"hp": 150, "atk": 40, "range": 1, "speed": 3, "cost": 150},
- "Archer": {"hp": 40, "atk": 30, "range": 5, "speed": 2, "cost": 50},
- "Crossbowman": {"hp": 60, "atk": 40, "range": 4, "speed": 2, "cost": 75},
- "Footman": {"hp": 80, "atk": 20, "range": 1, "speed": 2, "cost": 25},
- "DeathKnight": {"hp": 140, "atk": 20, "range": 1, "speed": 2, "cost": 200, "lifesteal": 10}
- }
- class Unit:
- def __init__(self, x, y, game, team, name, hp, atk, range, speed, cost, lifesteal=0):
- self.x = x
- self.y = y
- self.name = name
- self.hp = hp
- self.atk = atk
- self.range = range
- self.speed = speed
- self.cost = cost
- self.dead = False
- self.team = team
- self.game = game
- self.lifesteal = lifesteal
- self.grid = Grid(matrix=self.game.unit_map.unit_map)
- self.finder = AStarFinder()
- self.ready_to_attack = False
- class UnitFactory:
- _unit_configs = {}
- @classmethod
- def register_unit(cls, unit_type, config):
- UnitFactory._unit_configs[unit_type] = config
- @classmethod
- def create_unit(cls, unit_type, x, y, team, game):
- if unit_type not in UnitFactory._unit_configs:
- raise ValueError(f"Unknown unit type: {unit_type}")
- config = UnitFactory._unit_configs[unit_type]
- return Unit(x=x, y=y, game=game, team=team, name=unit_type, **config)
Advertisement
Add Comment
Please, Sign In to add comment