예제 #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()}");
        }
예제 #2
0
        public void KnifeSwordDecoratorTest()
        {
            VehicleDecorator rocketDecorator = new KnifeDecorator(new Rocket());

            Assert.AreEqual(4, rocketDecorator.GetAtt());

            rocketDecorator = new SwordDecorator(rocketDecorator);
            Assert.AreEqual(12, rocketDecorator.GetAtt());
        }
예제 #3
0
        public void ShieldSwordDecoratorTest()
        {
            VehicleDecorator carDecorator = new ShieldDecorator(new Car());

            carDecorator = new SwordDecorator(carDecorator);

            Assert.AreEqual(8, carDecorator.GetDef());
            Assert.AreEqual(8, carDecorator.GetAtt());
        }
예제 #4
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()}");
        }
예제 #5
0
        public ActionResult DoSpecialAction(int position, IArmy myArmy, IArmy enemyArmy, Random random = null)
        {
            if (random == null)
            {
                random = new Random();
            }

            double probability = random.NextDouble();

            //для улучшения сгенерированная вероятность должна принадлежать промежутку [0, ImprovementHeavyUnitProbability)
            if (probability >= ImprovementHeavyUnitProbability)
            {
                return(ActionResult.Empty);
            }

            int[] availibleForImprovement = GetAvailibleForImprovement(position, myArmy).ToArray();

            if (availibleForImprovement.Length == 0)
            {
                return(ActionResult.Empty);
            }

            int index  = availibleForImprovement[random.Next(0, availibleForImprovement.Length)];
            int action = random.Next(0, 4);

            IHeavyInfantry unit = myArmy.GetUnit(index) as IHeavyInfantry;

            switch (action)
            {
            case 0:
                if (unit.ContainsImprovement(typeof(HelmetDecorator)))
                {
                    return(ActionResult.Empty);
                }
                unit = new HelmetDecorator(unit);
                myArmy.ReplaceUnit(unit, index);
                break;

            case 1:
                if (unit.ContainsImprovement(typeof(HorseDecorator)))
                {
                    return(ActionResult.Empty);
                }
                unit = new HorseDecorator(unit);
                myArmy.ReplaceUnit(unit, index);
                break;

            case 2:
                if (unit.ContainsImprovement(typeof(ShieldDecorator)))
                {
                    return(ActionResult.Empty);
                }
                unit = new ShieldDecorator(unit);
                myArmy.ReplaceUnit(unit, index);
                break;

            case 3:
                if (unit.ContainsImprovement(typeof(SwordDecorator)))
                {
                    return(ActionResult.Empty);
                }
                unit = new SwordDecorator(unit);
                myArmy.ReplaceUnit(unit, index);
                break;

            default:
                return(ActionResult.Empty);
            }
            return(new ActionResult(this, unit, ActionResultType.Improvement));
        }