// Better game implementation public static void BrokerChain() { var game = new Game(); var goblin = new Creature2(game, "Strong goblin", 3, 3); // in real example you can specify game in DI WriteLine(goblin); using (new DoubleAttackModifier2(game, goblin)) { WriteLine(goblin); using (new IncreasingDefenseModifier2(game, goblin)) { WriteLine(goblin); } } WriteLine(goblin); // console output: //Name: Strong goblin, Attack: 3, Defense: 3 //Name: Strong goblin, Attack: 6, Defense: 3 //Name: Strong goblin, Attack: 6, Defense: 5 //Name: Strong goblin, Attack: 3, Defense: 3 // beacause of Dispose }
public DoubleAttackModifier2(Game game, Creature2 creature) : base(game, creature) { }
public IncreasingDefenseModifier2(Game game, Creature2 creature) : base(game, creature) { }
protected CreateModifier2(Game game, Creature2 creature) { this.game = game ?? throw new ArgumentNullException(nameof(game)); this.creature = creature ?? throw new ArgumentNullException(nameof(creature)); game.Queries += Handle; }