Me and 2 friend develop Trading Card Game : “Animals Card”. My two friends test the game with real card for the card’s strategy, balances cards etc…
We have 5 category of card (savannah, ocean …) and two types of card: Animal and Booster.
Each animal have 2 actions. There are 5 types actions: Magic, Life, Attack, Invocation and Dead. Each action have a description, for example with antelope card
Action “Indeed Pack”: Give 30 life point at alliee animal.
There are many action with many specifications.
I have a question for integration of action.
Do you think, i need to write a method for each action? For example (with the same example)
(Very fast example )
void IndeedPack (Card allieeCard)
{
allieeCard.LifePoint += 30;
}
I must realize this for each action with their specifications?
Do you think is the best solution?
I think you need to define a class for each of these 5 types of actions. The class should expose public properties for the description, and any extra data it needs to define what it does. For example:
public class LifeAction : MonoBehaviour {
public string description;
public int lifeAdd = 10;
public void Apply(Card card) {
card.LifePoint += lifeAdd;
}
}
Now you can throw this action onto each of your cards that needs to add life points, and define exactly how many life points it adds in each case (as well as the description of course).
When it’s time to apply the card, you can iterate through the components on the card, and invoke the Apply method for each one. (If you want to get fancy there are ways to make this easier, for example using interfaces, or even the Unity messaging system, but if you’re new to C# and/or Unity, you might keep it simple for now.)
So, if i understand, i need to identify the comon action by type action and create method for the same action. And for other, create special method for the “special” action?