
[ad_1]
I’ve a few issues for this structure
Cards with Multiple Effects
Right now, you may have a card that when performed, attracts two playing cards. In the long run, 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 great structure will will let you re-use code between playing cards with comparable results.
Cards which set off apart from when performed
In a extra difficult sport, you may need a card that claims, “When you draw this card, take two harm.”
A great structure will help bizarre playing cards like this.
If you might be working in C# (like with Unity), there may be a chic language characteristic that may assist right here known as Events.
Each occasion can take an arbitrary variety of subscribers, and fires all of them so as when these occasions are triggered.
Here is a few instance code.
public delegate void CardImpact(CardParticipant participant, CardGameObject? goal);
public class Card
{
public occasion CardImpact Played;
public occasion CardImpact Drawn;
public occasion CardImpact Discarded;
// TODO: Write some code right here to invoke the occasions after they come up.
}
public static class InstanceCards
{
public static Card DrawTwo()
{
var card = new Card();
card.Played += InstanceCardEffects.Draw(2);
return card;
}
public static Card DrawThreeDiscardOne()
{
var card = new Card();
card.Played += InstanceCardEffects.Draw(3);
card.Played += InstanceCardEffects.Discard(1);
return card;
}
public static Card TakeDamageWhenDrawn()
{
var card = new Card();
card.Drawn += InstanceCardEffects.TakeDamage(2);
return card;
}
}
public static class InstanceCardEffects
{
public static CardImpact Draw(int quantity)
{
return (participant, goal) => participant.Draw(quantity);
}
public static CardImpact Discard(int quantity)
{
return (participant, goal) => participant.Discard(quantity);
}
public static CardImpact DealDamage(int quantity)
{
return (participant, goal) => participant.DealDamage(goal, quantity);
}
public static CardImpact TakeDamage(int quantity)
{
return (participant, goal) => participant.DealDamage(participant, quantity);
}
}
```
[ad_2]