mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-03-13 20:56:54 +01:00
module 7 01 WIP
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from ex0.Card import Card
|
from ex0.Card import Card
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
class ArtifactCard(Card):
|
class ArtifactCard(Card):
|
||||||
@@ -10,7 +11,17 @@ class ArtifactCard(Card):
|
|||||||
self.effect = effect
|
self.effect = effect
|
||||||
|
|
||||||
def play(self, game_state: dict) -> dict:
|
def play(self, game_state: dict) -> dict:
|
||||||
return super().play(game_state)
|
try:
|
||||||
|
res: dict[str, Union[int, str]] = {}
|
||||||
|
if game_state["mana"] < 2:
|
||||||
|
raise Exception("Not enough mana")
|
||||||
|
res["card_played"] = self.name
|
||||||
|
res["mana_used"] = 2
|
||||||
|
res["effect"] = self.effect
|
||||||
|
return res
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
|
return {}
|
||||||
|
|
||||||
def activate_ability(self) -> dict:
|
def activate_ability(self) -> dict:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from ex0.Card import Card
|
from ex0 import Card, CreatureCard
|
||||||
|
|
||||||
|
|
||||||
class Deck:
|
class Deck:
|
||||||
@@ -16,10 +16,32 @@ class Deck:
|
|||||||
print("{card_name} not found")
|
print("{card_name} not found")
|
||||||
|
|
||||||
def shuffle(self) -> None:
|
def shuffle(self) -> None:
|
||||||
pass
|
from random import shuffle
|
||||||
|
|
||||||
|
shuffle(self.cards)
|
||||||
|
|
||||||
def draw_card(self) -> Card:
|
def draw_card(self) -> Card:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_deck_stats(self) -> dict:
|
def get_deck_stats(self) -> dict:
|
||||||
pass
|
from . import ArtifactCard, SpellCard
|
||||||
|
|
||||||
|
creatures = 0
|
||||||
|
spells = 0
|
||||||
|
artifacts = 0
|
||||||
|
total_cost = 0.0
|
||||||
|
for card in self.cards:
|
||||||
|
if isinstance(card, CreatureCard):
|
||||||
|
creatures += 1
|
||||||
|
elif isinstance(card, ArtifactCard):
|
||||||
|
artifacts += 1
|
||||||
|
elif isinstance(card, SpellCard):
|
||||||
|
spells += 1
|
||||||
|
total_cost += card.cost
|
||||||
|
return {
|
||||||
|
"total_card": len(self.cards),
|
||||||
|
"creatures": creatures,
|
||||||
|
"spells": spells,
|
||||||
|
"artifacts": artifacts,
|
||||||
|
"avg_cost": total_cost / len(self.cards),
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from ex0.Card import Card
|
from ex0.Card import Card
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
class SpellCard(Card):
|
class SpellCard(Card):
|
||||||
@@ -9,7 +10,17 @@ class SpellCard(Card):
|
|||||||
self.effect_type = effect_type
|
self.effect_type = effect_type
|
||||||
|
|
||||||
def play(self, game_state: dict) -> dict:
|
def play(self, game_state: dict) -> dict:
|
||||||
return super().play(game_state)
|
try:
|
||||||
|
res: dict[str, Union[int, str]] = {}
|
||||||
|
if game_state["mana"] < 3:
|
||||||
|
raise Exception("Not enough mana")
|
||||||
|
res["card_played"] = self.name
|
||||||
|
res["mana_used"] = 3
|
||||||
|
res["effect"] = self.effect_type
|
||||||
|
return res
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
|
return {}
|
||||||
|
|
||||||
def resolve_effect(self, targets: list) -> dict:
|
def resolve_effect(self, targets: list) -> dict:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from . import ArtifactCard, Deck, SpellCard
|
||||||
|
|
||||||
|
__version__ = "1.0.0"
|
||||||
|
__author__ = "David GAILLETON"
|
||||||
|
__all__ = ["ArtifactCard", "Deck", "SpellCard"]
|
||||||
|
|||||||
Reference in New Issue
Block a user