I’ve a few issues for this structure
Playing cards with A number of Results
Proper now, you might have a card that when performed, attracts two playing cards. Sooner or later, you may want a card that pulls 3 playing cards after which discards 1, or a card that discards 1 after which attracts 3.
A superb structure will assist you to re-use code between playing cards with related results.
Playing cards which set off aside from when performed
In a extra difficult sport, you may need a card that claims, “Whenever you draw this card, take two injury.”
A superb structure will assist bizarre playing cards like this.
In case you are working in C# (like with Unity), there may be a chic language function that may assist right here referred to as Occasions.
Every occasion can take an arbitrary variety of subscribers, and fires all of them so as when these occasions are triggered.
Right here is a few instance code.
public delegate void CardEffect(CardPlayer participant, CardGameObject? goal);
public class Card
{
public occasion CardEffect Performed;
public occasion CardEffect Drawn;
public occasion CardEffect Discarded;
// TODO: Write some code right here to invoke the occasions after they come up.
}
public static class ExampleCards
{
public static Card DrawTwo()
{
var card = new Card();
card.Performed += ExampleCardEffects.Draw(2);
return card;
}
public static Card DrawThreeDiscardOne()
{
var card = new Card();
card.Performed += ExampleCardEffects.Draw(3);
card.Performed += ExampleCardEffects.Discard(1);
return card;
}
public static Card TakeDamageWhenDrawn()
{
var card = new Card();
card.Drawn += ExampleCardEffects.TakeDamage(2);
return card;
}
}
public static class ExampleCardEffects
{
public static CardEffect Draw(int quantity)
{
return (participant, goal) => participant.Draw(quantity);
}
public static CardEffect Discard(int quantity)
{
return (participant, goal) => participant.Discard(quantity);
}
public static CardEffect DealDamage(int quantity)
{
return (participant, goal) => participant.DealDamage(goal, quantity);
}
public static CardEffect TakeDamage(int quantity)
{
return (participant, goal) => participant.DealDamage(participant, quantity);
}
}
```