From ddb56264ae5cc3aceb00237505222eea95566313 Mon Sep 17 00:00:00 2001 From: David GAILLETON Date: Tue, 17 Feb 2026 15:27:05 +0100 Subject: [PATCH] module 7 ex1 + 0 --- 07/ex0/Card.py | 22 ++++++++++++++++++++++ 07/ex0/CreatureCard.py | 32 ++++++++++++++++++++++++++++++++ 07/ex0/__init__.py | 6 ++++++ 07/ex0/main.py | 20 ++++++++++++++++++++ 07/ex1/ArtifactCard.py | 16 ++++++++++++++++ 07/ex1/Deck.py | 6 ++++++ 07/ex1/SpellCard.py | 15 +++++++++++++++ 07/ex1/__init__.py | 0 07/ex1/main.py | 0 9 files changed, 117 insertions(+) create mode 100644 07/ex0/Card.py create mode 100644 07/ex0/CreatureCard.py create mode 100644 07/ex0/__init__.py create mode 100644 07/ex0/main.py create mode 100644 07/ex1/ArtifactCard.py create mode 100644 07/ex1/Deck.py create mode 100644 07/ex1/SpellCard.py create mode 100644 07/ex1/__init__.py create mode 100644 07/ex1/main.py diff --git a/07/ex0/Card.py b/07/ex0/Card.py new file mode 100644 index 0000000..2d15e3b --- /dev/null +++ b/07/ex0/Card.py @@ -0,0 +1,22 @@ +from abc import ABC, abstractmethod +from typing import Union + + +class Card(ABC): + def __init__(self, name: str, cost: int, rarity: str) -> None: + self.name = name + self.cost = cost + self.rarity = rarity + + @abstractmethod + def play(self, game_state: dict) -> dict: + pass + + def get_card_info(self) -> dict: + res = dict(self.__dict__) + return res + + def is_playable(self, available_mana: int) -> bool: + if available_mana > 5: + return True + return False diff --git a/07/ex0/CreatureCard.py b/07/ex0/CreatureCard.py new file mode 100644 index 0000000..ab0fb6e --- /dev/null +++ b/07/ex0/CreatureCard.py @@ -0,0 +1,32 @@ +from Card import Card +from typing import Dict, Union + + +class CreatureCard(Card): + def __init__( + self, name: str, cost: int, rarity: str, attack: int, health: int + ) -> None: + super().__init__(name, cost, rarity) + self.attack = attack + self.health = health + + def play(self, game_state: dict) -> dict: + try: + res: dict[str, Union[int, str]] = {} + if game_state["mana"] < 5: + raise Exception("Not enough mana") + res["card_played"] = self.name + res["mana_used"] = 5 + res["effect"] = "Creature summoned to battlefield" + return res + except Exception as err: + print(err) + return {} + + def attack_target(self, target: str) -> dict: + res: Dict[str, Union[int, str, bool]] = {} + res["attacker"] = self.name + res["target"] = target + res["damage_dealt"] = self.attack + res["combat_resolved"] = True + return res diff --git a/07/ex0/__init__.py b/07/ex0/__init__.py new file mode 100644 index 0000000..ab40060 --- /dev/null +++ b/07/ex0/__init__.py @@ -0,0 +1,6 @@ +from .Card import Card +from .CreatureCard import CreatureCard + +__version__ = "1.0.0" +__author__ = "moi" +__all__ = ["Card", "CreatureCard"] diff --git a/07/ex0/main.py b/07/ex0/main.py new file mode 100644 index 0000000..5c001c1 --- /dev/null +++ b/07/ex0/main.py @@ -0,0 +1,20 @@ +def main(): + from CreatureCard import CreatureCard + + game_state = {"player": "michel", "mana": 6} + print("=== DataDeck Card Foundation ===\n") + print("Testing Abstract Base Class Design:\n") + creature_card = CreatureCard("Fire Dragon", 5, "Legendary", 7, 5) + print(f"CreatureCard info:\n{creature_card.get_card_info()}") + print("\nPlaying Fire Dragon with 6 mana available:") + print(f"Playable: {creature_card.is_playable(game_state['mana'])}") + print(f"Play result: {creature_card.play(game_state)}") + print("\nFire Dragon attacks Goblin Warrior:") + print(f"Attack result: {creature_card.attack_target('Goblin Warrior')}") + print("\nTesting insufficient mana (3 available):") + print(f"Playable: {creature_card.is_playable(3)}") + print("\nAbstract pattern successfully demonstrated!") + + +if __name__ == "__main__": + main() diff --git a/07/ex1/ArtifactCard.py b/07/ex1/ArtifactCard.py new file mode 100644 index 0000000..7abe792 --- /dev/null +++ b/07/ex1/ArtifactCard.py @@ -0,0 +1,16 @@ +from ex0.Card import Card + + +class ArtifactCard(Card): + def __init__( + self, name: str, cost: int, rarity: str, durability: int, effect: str + ) -> None: + super().__init__(name, cost, rarity) + self.durability = durability + self.effect = effect + + def play(self, game_state: dict) -> dict: + return super().play(game_state) + + def activate_ability(self) -> dict: + pass diff --git a/07/ex1/Deck.py b/07/ex1/Deck.py new file mode 100644 index 0000000..e317ad5 --- /dev/null +++ b/07/ex1/Deck.py @@ -0,0 +1,6 @@ +from ex0.Card import Card + + +class Deck(): + def __init__(self) -> None: + self: diff --git a/07/ex1/SpellCard.py b/07/ex1/SpellCard.py new file mode 100644 index 0000000..63e8063 --- /dev/null +++ b/07/ex1/SpellCard.py @@ -0,0 +1,15 @@ +from ex0.Card import Card + + +class SpellCard(Card): + def __init__( + self, name: str, cost: int, rarity: str, effect_type: str + ) -> None: + super().__init__(name, cost, rarity) + self.effect_type = effect_type + + def play(self, game_state: dict) -> dict: + return super().play(game_state) + + def resolve_effect(self, targets: list) -> dict: + pass diff --git a/07/ex1/__init__.py b/07/ex1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/07/ex1/main.py b/07/ex1/main.py new file mode 100644 index 0000000..e69de29