Task 2 – Isolating side effects
The game loads enemy data from a file, processes it, and updates the game state. Refactor this function to isolate its side effects:
public void LoadAndProcessEnemyData(string filePath) { string jsonData = File.ReadAllText(filePath); List<Enemy> enemies = JsonConvert.DeserializeObject<List<Enemy>>(jsonData); foreach (var enemy in enemies) { enemy.Health *= GameState.DifficultyLevel; GameState.ActiveEnemies.Add(enemy); } Console.WriteLine($"Loaded {enemies.Count} enemies"); }