when choosing a character I currently have a base class
abstract class CharacterClass
{
public abstract void AbilityOne();
public abstract void AbilityTwo();
}
And my characters derive from this class
class Warrior : CharacterClass
{
public override void AbilityOne()
{
// implement ability one here
}
public override void AbilityTwo()
{
// implement ability two here
}
}
Lastly I use this code to select the Warrior
CharacterClass selectedClass = new Warrior(); // start the game as a Warrior
So this way works pretty fine. But when it comes to cooldowns etc. I want to stay with a clean code so I thought about creating a Ability class.
My abstract parent class
abstract class CharacterClass
{
public Ability AbilityOne { get; set; }
public Ability AbilityTwo { get; set; }
}
The Warrior class
class Warrior : CharacterClass
{
public Warrior()
{
// Set the new Abilities
AbilityOne = new Ability(3, Smash()); // pass in the method as a parameter ??
AbilityTwo = new Ability(7, Shieldblock());
}
private void Smash()
{
// Ability 1
}
private void ShieldBlock()
{
// Ability 2
}
}
And my skill class
class Ability
{
public Ability(int cooldown, [the ability method here])
{
CoolDown = cooldown;
TheAbility = ? the ability parameter ?
}
public int CoolDown { get; set; }
public void TheAbility(){}
}
So the warrior will pass in his two skills and creates two ability objects. In the game I could write
CharacterClass selectedClass = new Warrior();
selectedClass.AbilityOne();
and this would result into a smash with a cooldown of 3 seconds. Is this possible to implement .. somehow .. ?