public void Add(CreatureModifier cm) { if (next != null) { next.Add(cm); } else { next = cm; } }
// this way is not good and very painfull to implement // not a GoF good way public static void MethodChain() { var goblin = new Creature("Goblin", 2, 2); WriteLine(goblin); var root = new CreatureModifier(goblin); root.Add(new NoBonusesModifier(goblin)); WriteLine("Let's doubling the goblin attack"); root.Add(new DoubleAttackModifier(goblin)); WriteLine("Let's increasing the goblin defense"); root.Add(new IncreasingDefenseModifier(goblin)); root.Handle(); WriteLine(goblin); }