Exemplo n.º 1
0
 public void Add(CreatureModifier cm)
 {
     if (next != null)
     {
         next.Add(cm);
     }
     else
     {
         next = cm;
     }
 }
Exemplo n.º 2
0
        public void Add(CreatureModifier creatureModifier)
        {
            if (next == null)
            {
                next = creatureModifier;
            }

            else
            {
                next.Add(creatureModifier);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var goblin = new Creature("goblin", 2, 2);

            Console.WriteLine(goblin);

            var root = new CreatureModifier(goblin);

            Console.WriteLine("Let's double the goblin's attack");
            root.Add(new DoubleAttackModifier(goblin));
            root.Add(new IncreasedDefenseModifier(goblin));
            root.Handle();
            Console.WriteLine(goblin);
        }
Exemplo n.º 4
0
        public static void MethodChainRun()
        {
            var goblin = new Creature("Goblin", 1, 1);

            WriteLine(goblin);

            var root = new CreatureModifier(goblin);

            root.Add(new DoubleAttackModifier(goblin));
            root.Add(new DoubleAttackModifier(goblin));
            root.Add(new IncreaseDefenseModifier(goblin));

            root.Handle();
            WriteLine(goblin);
        }
Exemplo n.º 5
0
        static 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($"Attempting to double {goblin.name}'s attack!");
            root.Add(new DoubleAttackModifier(goblin));
            Console.WriteLine("Modifier nullified!");

            root.Handle(); // checks for modifiers
            Console.WriteLine(goblin);
        }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            var goblin = new Creature("Goblin", 2, 2);
            var root   = new CreatureModifier(goblin);

            WriteLine(goblin);

            WriteLine($"Let's Double goblin's attack!!!");
            root.Add(new DoubleAttackModifier(goblin));

            root.Add(new NoBonusesModifier(goblin));

            WriteLine($"Let's Increase goblins defense!!!");
            root.Add(new IncreasedDefenseModifier(goblin));

            root.Handle();

            WriteLine(goblin);
        }
        static void Main()
        {
            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);
        }
Exemplo n.º 8
0
        // Modification of base object
        private static void MethodChainExample()
        {
            var goblin = new Creature("Goblin", 2, 2);

            Console.WriteLine(goblin);

            var root = new CreatureModifier(goblin);

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

            Console.WriteLine("Let's block further additional goblin modifiers");
            root.Add(new StatsModBlockerModifier(goblin));

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

            root.Handle();
            Console.WriteLine(goblin);
        }
        // change to Main to run.
        public static void none(string[] args)
        {
            var goblin = new Creature("Goblin", 2, 2);

            Console.WriteLine(goblin);
            var root = new CreatureModifier(goblin);

            // casts protection spell where it cannot be buffed (silenced) COOL!!!!!!!!!!!!!
            // prevents walk of linked list aka no chain of responsibility traversal.
            root.Add(new SilenceModifier(goblin));

            Console.WriteLine("Let's double the goblin's attack");
            // adding another modifier to the chain of responsibility
            root.Add(new DoubleAttackModifier(goblin));
            Console.WriteLine("Let's increase the goblin's defense");
            root.Add(new IncreasedDefenseModifer(goblin));
            root.Handle();
            Console.WriteLine(goblin);

            // Downside - method chain implemented this way permanently changes the creature
            // so that modifiers cannot be removed. We would have to follow the entire linked list
            // and then recalculate original state of creature.
            // See CoR_BrokerChain for better implementation.
        }