mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-03-14 05:06:55 +01:00
module 7 ex3 WIP
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
from . import ArtifactCard, Deck, SpellCard
|
from .ArtifactCard import ArtifactCard
|
||||||
|
from .SpellCard import SpellCard
|
||||||
|
from .Deck import Deck
|
||||||
|
|
||||||
__version__ = "1.0.0"
|
__version__ = "1.0.0"
|
||||||
__author__ = "David GAILLETON"
|
__author__ = "David GAILLETON"
|
||||||
|
|||||||
9
07/ex3/AggresiveStrategy.py
Normal file
9
07/ex3/AggresiveStrategy.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
from .GameStrategy import GameStrategy
|
||||||
|
|
||||||
|
|
||||||
|
class AgressiveStrategy(GameStrategy):
|
||||||
|
def execute_turn(self, hand: list, battlefield: list) -> dict: ...
|
||||||
|
|
||||||
|
def get_strategy_name(self) -> str: ...
|
||||||
|
|
||||||
|
def prioritize_targets(self, available_targets: list) -> list: ...
|
||||||
23
07/ex3/CardFactory.py
Normal file
23
07/ex3/CardFactory.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from ex0 import Card
|
||||||
|
|
||||||
|
|
||||||
|
class CardFactory(ABC):
|
||||||
|
@abstractmethod
|
||||||
|
def create_creature(
|
||||||
|
self, name_or_power: str | int | None = None
|
||||||
|
) -> Card: ...
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def create_spell(self, name_or_power: str | int | None = None) -> Card: ...
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def create_artifact(
|
||||||
|
self, name_or_power: str | int | None = None
|
||||||
|
) -> Card: ...
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def create_themed_deck(self, size: int) -> dict: ...
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_supported_types(self) -> dict: ...
|
||||||
46
07/ex3/FantasyCardFactory.py
Normal file
46
07/ex3/FantasyCardFactory.py
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
from .CardFactory import CardFactory
|
||||||
|
from random import choice
|
||||||
|
from ex0 import Card, CreatureCard
|
||||||
|
from ex1 import SpellCard, ArtifactCard
|
||||||
|
|
||||||
|
creature_cards = [
|
||||||
|
CreatureCard("Fire Dragon", 20, "Rare", 7, 20),
|
||||||
|
CreatureCard("Goblin Warrior", 12, "Common", 4, 10),
|
||||||
|
]
|
||||||
|
|
||||||
|
spell_cards = [
|
||||||
|
SpellCard("Fire Ball", 5, "Rare", "Decrase health by 1 for 3 round"),
|
||||||
|
SpellCard("Ice Spike", 3, "Common", "Reduce damage by 2 for 1 round"),
|
||||||
|
SpellCard(
|
||||||
|
"Lightning bolt", 10, "Legendary", "Card can't play for 3 round"
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
artifact_cards = [
|
||||||
|
ArtifactCard(
|
||||||
|
"Mana Ring", 2, "Common", 3, "Increase mana by 1 for each round"
|
||||||
|
),
|
||||||
|
ArtifactCard("Witch Staff", 6, "Legendary", 5, ""),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class FantasyCardFactory(CardFactory):
|
||||||
|
def create_creature(self, name_or_power: str | int | None = None) -> Card:
|
||||||
|
card = choice(creature_cards)
|
||||||
|
if isinstance(name_or_power, str):
|
||||||
|
card.name = name_or_power
|
||||||
|
elif isinstance(name_or_power, int):
|
||||||
|
card.attack = name_or_power
|
||||||
|
return card
|
||||||
|
|
||||||
|
def create_spell(self, name_or_power: str | int | None = None) -> Card:
|
||||||
|
return super().create_spell(name_or_power)
|
||||||
|
|
||||||
|
def create_artifact(self, name_or_power: str | int | None = None) -> Card:
|
||||||
|
return super().create_artifact(name_or_power)
|
||||||
|
|
||||||
|
def create_themed_deck(self, size: int) -> dict:
|
||||||
|
return super().create_themed_deck(size)
|
||||||
|
|
||||||
|
def get_supported_types(self) -> dict:
|
||||||
|
return super().get_supported_types()
|
||||||
0
07/ex3/GameEngine.py
Normal file
0
07/ex3/GameEngine.py
Normal file
12
07/ex3/GameStrategy.py
Normal file
12
07/ex3/GameStrategy.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
class GameStrategy(ABC):
|
||||||
|
@abstractmethod
|
||||||
|
def execute_turn(self, hand: list, battlefield: list) -> dict: ...
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_strategy_name(self) -> str: ...
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def prioritize_targets(self, available_targets: list) -> list: ...
|
||||||
0
07/ex3/__init__.py
Normal file
0
07/ex3/__init__.py
Normal file
0
07/ex3/main.py
Normal file
0
07/ex3/main.py
Normal file
Reference in New Issue
Block a user