Пример #1
0
 public void Add(CreatureModifier cm) // Creating the chain.
 {
     if (next != null)
     {
         next.Add(cm);
     }
     else
     {
         next = cm;
     }
 }
Пример #2
0
 public void Add(CreatureModifier cm)
 {
     if (next != null)
     {
         next.Add(cm);
     }
     else
     {
         next = cm;
     }
 }
Пример #3
0
        static void Main(string[] args)
        {
            var goblin = new Creature("Goblin", 2, 2);

            Console.WriteLine(goblin);

            var root = new CreatureModifier(goblin);

            root.Add(new NoModifierSpell(goblin));    // Stops modification on creature.

            root.Add(new AttackModifier(goblin));
            root.Add(new DefenceModifier(goblin));

            root.Handle();

            Console.WriteLine(goblin);
        }
        static void Main(string[] args)
        {
            // METHOD CHAIN
            var goblin = new Creature("Goblin", 2, 2);

            Console.WriteLine(goblin);

            var root = new CreatureModifier(goblin);

            root.Add(new NoBonusesModifier(goblin));

            Console.WriteLine("Let's double goblin's attack...");

            root.Add(new DoubleAttackModifier(goblin));

            Console.WriteLine("Let's increase goblin's defense");

            root.Add(new IncreaseDefenseModifier(goblin));

            // eventually...
            root.Handle();

            Console.WriteLine(goblin);

            // BROKER CHAIN
            var game     = new Game();
            var goblinBc = new CreatureBC(game, "Strong Goblin", 3, 3);

            Console.WriteLine(goblinBc);

            using (new DoubleAttackModifierBC(game, goblinBc))
            {
                Console.WriteLine(goblinBc);

                using (new IncreaseDefenseModifierBC(game, goblinBc))
                {
                    Console.WriteLine(goblinBc);
                }
            }

            Console.WriteLine(goblinBc);

            Console.ReadLine();
        }
Пример #5
0
        void Main(string[] args)
        {
            var goblin = new Creature("Goblin", 2, 2);

            Console.WriteLine(goblin);

            var root = new CreatureModifier(goblin);

            root.Add(new NoBonusesModifier(goblin));

            Console.WriteLine("Let's double the goblin's attack");
            root.Add(new DoubleAttackModifier(goblin));

            Console.WriteLine("Let's increase goblin's defense");
            root.Add(new IncreaseDefenseModifier(goblin));

            root.Handle();

            Console.WriteLine(goblin);
        }