module 7 ex 0 to 2

This commit is contained in:
2026-03-02 15:49:13 +01:00
parent 2cb7f24a8e
commit 164445bb42
12 changed files with 189 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
from ex0.Card import Card
from ex0 import Card
from typing import Union
@@ -24,4 +24,11 @@ class ArtifactCard(Card):
return {}
def activate_ability(self) -> dict:
pass
if self.durability <= 0:
return {
"name": self.name,
"durability": self.durability,
"destroyed": True,
}
self.durability -= 1
return self.get_card_info()

View File

@@ -21,10 +21,12 @@ class Deck:
shuffle(self.cards)
def draw_card(self) -> Card:
pass
self.shuffle()
return self.cards.pop()
def get_deck_stats(self) -> dict:
from . import ArtifactCard, SpellCard
from .ArtifactCard import ArtifactCard
from .SpellCard import SpellCard
creatures = 0
spells = 0

View File

@@ -1,4 +1,4 @@
from ex0.Card import Card
from ex0 import Card
from typing import Union
@@ -10,7 +10,7 @@ class SpellCard(Card):
self.effect_type = effect_type
def play(self, game_state: dict) -> dict:
try:
try:
res: dict[str, Union[int, str]] = {}
if game_state["mana"] < 3:
raise Exception("Not enough mana")
@@ -22,5 +22,5 @@ class SpellCard(Card):
print(err)
return {}
def resolve_effect(self, targets: list) -> dict:
pass
def resolve_effect(self, targets: list) -> dict:
return {"card": self.name, "targets": targets, "resolved": True}

View File

@@ -0,0 +1,32 @@
def main():
from .Deck import Deck
from .SpellCard import SpellCard
from .ArtifactCard import ArtifactCard
from ex0 import CreatureCard
print("=== DataDeck Deck Builder ===\n")
deck = Deck()
print("Building deck with different card types...")
deck.add_card(
SpellCard("Lightning Bolt", 5, "Common", "Deal 3 dammage to target")
)
deck.add_card(
ArtifactCard(
"Mana Crystal", 7, "Medium", 1, "Permanent: +1 mana per turn"
)
)
deck.add_card(CreatureCard("Fire dragon", 10, "Rare", 15, 20))
print(f"Deck stats: {deck.get_deck_stats()}")
print("\nDrawing and playing cards:\n")
for _ in range(deck.get_deck_stats()["total_card"]):
try:
card = deck.draw_card()
print(f"Drew: {card.name} ({card.__class__.__name__})")
print(f"{card.play({'mana': 5})}\n")
except Exception as err:
print(err)
print("Polymorphism in action: Same interface, different card behaviors!")
if __name__ == "__main__":
main()