Пример #1
0
        static void Main(string[] args)
        {
            #region Method Chain
            //var goblin = new Creature("Goblin", 2, 3);
            //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);
            #endregion

            #region Broker Chain
            var game   = new Game();
            var goblin = new Creature1(game, "string goblin", 3, 3);
            Console.WriteLine(goblin);

            using (new DoubleAttackModifier1(game, goblin))
            {
                Console.WriteLine(goblin);
                using (new IncreaeDefenseModifier1(game, goblin))
                {
                    Console.WriteLine(goblin);
                }
            }

            Console.WriteLine(goblin);
            #endregion
        }
Пример #2
0
 public DoubleAttackModifier1(Game game, Creature1 creature) : base(game, creature)
 {
 }
Пример #3
0
 public IncreaeDefenseModifier1(Game game, Creature1 creature) : base(game, creature)
 {
 }
Пример #4
0
 protected CreatureModifier1(Game game, Creature1 creature)
 {
     this.game     = game ?? throw new ArgumentNullException(paramName: nameof(game));
     this.creature = creature ?? throw new ArgumentNullException(paramName: nameof(creature));
     game.Queries += Handle;
 }