Beispiel #1
0
        public void AddDefense(Vehicle car, Defense defense)
        {
            var carDecorator = new VehicleDecorator(car);

            switch (defense)
            {
            case Defense.Armor:
                carDecorator = new ArmorDecorator(carDecorator);
                break;

            case Defense.Gloves:
                carDecorator = new GlovesDecorator(carDecorator);
                break;

            case Defense.Helmet:
                carDecorator = new HelmetDecorator(carDecorator);
                break;

            case Defense.Shield:
                carDecorator = new ShieldDecorator(carDecorator);
                break;
            }

            Console.WriteLine($"Def: {carDecorator.GetDef()}");
        }
Beispiel #2
0
        public void ArmorAxeDecoratorTest()
        {
            VehicleDecorator boatDecorator = new ArmorDecorator(new Boat());

            boatDecorator = new AxeDecorator(boatDecorator);

            Assert.AreEqual(10, boatDecorator.GetDef());
            Assert.AreEqual(7, boatDecorator.GetAtt());
        }
Beispiel #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()}");
        }
Beispiel #4
0
        public bool ArmorUp(int x, int y, int arenaId, string socketId)
        {
            ArmorSelection armorSelection = GetArmorSelection(socketId);
            Cell           cell           = ReturnCell(x, y, arenaId);

            if (cell != null)
            {
                if (cell.IsArmored == false && armorSelection.ArmorSize >= 1)
                {
                    //cell.IsArmored = true;
                    ArmorDecorator decorator = new ArmorDecorator(cell);
                    decorator.AddArmor();
                    armorSelection.ArmorSize--;
                    _context.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
Beispiel #5
0
        public IUnit DoSpecialAction(IUnit unit)
        {
            if (unit is IAmmunition)
            {
                if (((IAmmunition)unit).Access == null)
                {
                    ((IAmmunition)unit).Access = new Dictionary <int, string>();
                }

                if (((IAmmunition)unit).Access.Count == 4)
                {
                    return(null);
                }

                Component accessory = new AccessoryComponent();

                Random random = new Random();
                int    cloth  = 0;
                bool   end    = true;

                while (end)
                {
                    cloth = random.Next(0, 4);
                    if (((IAmmunition)unit).Access.ContainsKey(cloth))
                    {
                        continue;
                    }
                    else
                    {
                        end = false;
                    }
                }
                var nameAmmunition = "";
                switch (cloth)
                {
                case 0:
                    nameAmmunition = "Helmet";
                    accessory      = new HelmetDecorator(accessory, unit);
                    accessory.AddAccessory();
                    break;

                case 1:
                    nameAmmunition = "Armor";
                    accessory      = new ArmorDecorator(accessory, unit);
                    accessory.AddAccessory();
                    break;

                case 2:
                    nameAmmunition = "Horse";
                    accessory      = new HorseDecorator(accessory, unit);
                    accessory.AddAccessory();
                    break;

                case 3:
                    nameAmmunition = "Peak";
                    accessory      = new PeakDecorator(accessory, unit);
                    accessory.AddAccessory();
                    break;
                }
                ((IAmmunition)unit).Access.Add(cloth, nameAmmunition);
                return(accessory.GetUnit());
            }

            return(null);
        }