The engine needs a way to broadcast state changes (e.g., turn progression, damage taken) to external systems like the UI or a Combat Log, as well as to internal game logic (e.g., regeneration effects).
We decided to use standard C# Events (EventHandler<T>) exposed on the core interfaces.
ITurnManager: ExposesTurnChanged,RoundChanged, andCombatEnded.IHitPoints: ExposesDamageTaken,Healed, andDied.
- Event Arguments: Defined strongly-typed arguments (e.g.,
TurnChangedEventArgs,DamageTakenEventArgs) to pass relevant context. - Standard Components:
StandardTurnManagerandStandardHitPointsimplement the triggering logic.
- Pros:
- Idiomatic: Uses standard .NET patterns familiar to developers.
- Type-Safe: Event arguments ensure consumers get the correct data.
- Decoupled: Consumers subscribe to interfaces, not concrete implementations.
- Cons:
- Memory Management: Subscribers must unsubscribe to avoid memory leaks (standard event caveat).
Accepted and Implemented.