Task 1 – Recursive enemy count
Steve’s game has a hierarchical structure of enemy waves, where each wave can contain both individual enemies and sub-waves. Implement a recursive function, CountAllEnemies, that navigates through a Wave object (which can contain both Enemy objects and Wave objects) and returns the total count of enemies found within that wave, including all its sub-waves (flying, armored, quick, etc.):
public interface IWaveContent {}
public class Enemy : IWaveContent
{
public string Name { get; set; }
}
public class Wave : IWaveContent
{
public List<IWaveContent> Contents { get; set; } = new();
}
// Implement this method
int CountAllEnemies(Wave wave)
{
// Your recursive logic here
} Test your method with a Wave containing a mix of Enemy objects and Wave objects to ensure that it accurately counts all enemies, including those in nested sub-waves.