Case study – putting it all together
Here, we’ll bring together all the elements we’ve discussed so far: higher-order functions, delegates, actions, funcs, predicates, and LINQ methods. We’ll provide a comprehensive, real-world example and analyze the code, step by step.
Imagine we are developing a mobile tower defense game. This game involves managing towers, handling enemy waves, and upgrading tower capabilities.
Here’s an outline of the classes we’ll use:
public class Tower
{
public string Type { get; set; }
public int Damage { get; set; }
public bool IsUpgraded { get; set; }
}
public class Game
{
private List<Tower> _towers { get; set; }
public IEnumerable<Tower> FilterTowers(Func<Tower, bool> predicate) { /* … */ }
public event Action<Tower> TowerUpgraded...