Example #1
0
        public void AddWeapon(Vehicle car, Weapon weapon)
        {
            var carDecorator = new VehicleDecorator(car);

            switch (weapon)
            {
            case Weapon.Axe:
                carDecorator = new AxeDecorator(carDecorator);
                break;

            case Weapon.Bow:
                carDecorator = new BowDecorator(carDecorator);
                break;

            case Weapon.Gun:
                carDecorator = new GunDecorator(carDecorator);
                break;

            case Weapon.Knife:
                carDecorator = new KnifeDecorator(carDecorator);
                break;

            case Weapon.Sword:
                carDecorator = new SwordDecorator(carDecorator);
                break;
            }

            Console.WriteLine($"Att: {carDecorator.GetAtt()}");
        }
Example #2
0
        public void GlovesBowDecoratorTest()
        {
            VehicleDecorator planeDecorator = new GlovesDecorator(new Plane());

            planeDecorator = new BowDecorator(planeDecorator);

            Assert.AreEqual(2, planeDecorator.GetDef());
            Assert.AreEqual(8, planeDecorator.GetAtt());
        }
Example #3
0
        public static void DecoratorUsage()
        {
            VehicleDecorator carDecorator = new ShieldDecorator(new Car());

            System.Console.WriteLine($"Att: {carDecorator.GetAtt()}, Def: {carDecorator.GetDef()}");
            carDecorator = new SwordDecorator(carDecorator);
            System.Console.WriteLine($"Att: {carDecorator.GetAtt()}, Def: {carDecorator.GetDef()}");
            carDecorator = new ArmorDecorator(carDecorator);
            carDecorator = new BowDecorator(carDecorator);
            System.Console.WriteLine($"Att: {carDecorator.GetAtt()}, Def: {carDecorator.GetDef()}");
        }