游戏可以运行
This commit is contained in:
87
card_game/card.py
Normal file
87
card_game/card.py
Normal file
@@ -0,0 +1,87 @@
|
||||
"""Card class: represents a single card (unit or order)."""
|
||||
|
||||
from card_game.config import CARD_DATABASE, FACTION_COLORS, KEYWORDS
|
||||
|
||||
|
||||
class Card:
|
||||
def __init__(self, card_id):
|
||||
data = CARD_DATABASE[card_id]
|
||||
self.id = data["id"]
|
||||
self.name = data["name"]
|
||||
self.faction = data["faction"]
|
||||
self.card_type = data["type"] # "unit" or "order"
|
||||
self.cost = data["cost"]
|
||||
self.op_cost = data.get("op_cost", 0)
|
||||
self.description = data["description"]
|
||||
self.rarity = data["rarity"]
|
||||
|
||||
# Unit-specific
|
||||
self.unit_type = data.get("unit_type", None)
|
||||
self.attack = data.get("attack", 0)
|
||||
self.defense = data.get("defense", 0)
|
||||
self.max_hp = data.get("max_hp", 0)
|
||||
self.abilities = data.get("abilities", [])
|
||||
|
||||
# Order-specific
|
||||
self.effect_type = data.get("effect_type", None)
|
||||
self.effect_params = data.get("effect_params", {})
|
||||
|
||||
# Runtime state
|
||||
self.current_hp = self.max_hp
|
||||
self.zone = "hand" # "hand", "support", "frontline"
|
||||
self.slot = -1
|
||||
self.can_attack = False
|
||||
self.has_moved = False
|
||||
self.has_attacked = False
|
||||
self.turn_played = 0
|
||||
|
||||
# Buff tracking: list of (attack_bonus, defense_bonus, turns_remaining)
|
||||
self.buffs = []
|
||||
|
||||
def take_damage(self, amount):
|
||||
self.current_hp -= amount
|
||||
|
||||
def is_alive(self):
|
||||
return self.current_hp > 0
|
||||
|
||||
def get_effective_attack(self):
|
||||
bonus = sum(b[0] for b in self.buffs)
|
||||
return self.attack + bonus
|
||||
|
||||
def get_effective_defense(self):
|
||||
bonus = sum(b[1] for b in self.buffs)
|
||||
return self.defense + bonus
|
||||
|
||||
def reset_turn_flags(self):
|
||||
self.can_attack = False
|
||||
self.has_moved = False
|
||||
self.has_attacked = False
|
||||
# Tick buffs
|
||||
self.buffs = [(a, d, t - 1) for a, d, t in self.buffs if t > 1]
|
||||
|
||||
def can_move_and_attack(self):
|
||||
return "charge" in self.abilities
|
||||
|
||||
def is_ranged(self):
|
||||
return "ranged" in self.abilities
|
||||
|
||||
def get_keywords(self):
|
||||
result = []
|
||||
for ability in self.abilities:
|
||||
base = ability.split(":")[0]
|
||||
if base in KEYWORDS:
|
||||
kw = KEYWORDS[base]
|
||||
desc = kw["desc"]
|
||||
if ":" in ability:
|
||||
param = ability.split(":")[1]
|
||||
desc = desc.replace("X", param)
|
||||
result.append((kw["icon"], kw["name"], desc, kw["color"]))
|
||||
return result
|
||||
|
||||
def get_color(self):
|
||||
if self.faction == "neutral":
|
||||
return (110, 105, 95)
|
||||
return FACTION_COLORS.get(self.faction, (128, 128, 128))
|
||||
|
||||
def __repr__(self):
|
||||
return f"Card({self.name})"
|
||||
Reference in New Issue
Block a user