Exemple #1
0
 public void AddAirCraft(IAirCraft aircraft)
 {
     if (aircraft != null)
     {
         _aircraftlist.Add(aircraft);
     }
 }
Exemple #2
0
        public string AddAircraft(IList <string> arguments)
        {
            string  aircraftType = arguments[0];
            string  model        = arguments[1];
            double  weight       = double.Parse(arguments[2]);
            decimal price        = decimal.Parse(arguments[3]);
            int     attack       = int.Parse(arguments[4]);
            int     defense      = int.Parse(arguments[5]);
            int     hitPoints    = int.Parse(arguments[6]);

            IAirCraft aircraft =
                this.aircraftFactory.CreateAirCraft(aircraftType, model, weight, price, attack, defense, hitPoints);

            if (aircraft == null)
            {
                throw new ArgumentNullException("This AirCraft type does not exist!");
            }

            this.aircrafts.Add(aircraft.Model, aircraft);

            return(string.Format(
                       GlobalConstants.AircraftSuccessMessage,
                       aircraftType,
                       aircraft.Model));
        }
        public IAirCraft CreateAirCraft
            (string aircraftType, string model, double weight, decimal price, int attack, int defense, int hitPoints)
        {
            Type type = Assembly.GetCallingAssembly()
                        .GetTypes()
                        .FirstOrDefault(t => t.Name == aircraftType);

            IAirCraft aircraft = (IAirCraft)Activator.CreateInstance(type, model, weight, price, attack, defense, hitPoints, new AircraftAssembler());

            return(aircraft);
        }
Exemple #4
0
        public IAirCraft GetAirCraft(string id)
        {
            IAirCraft _item = null;

            try
            {
                _item = _aircraftlist.Where(x => x.ID == id).First();
            }

            catch (InvalidOperationException)
            {
                Console.WriteLine("Aircraft with index {0} is not found", id);
            }
            return(_item);
        }
        public IAirCraft CreateAirCraft
            (string aircraftType, string model, double weight, decimal price, int attack, int defense, int hitPoints)
        {
            Type type = Assembly.GetCallingAssembly()
                        .GetTypes()
                        .FirstOrDefault(t => t.Name == aircraftType);

            if (type == null)
            {
                throw new ArgumentNullException("This AirCraft type does not exist!");
            }

            IAirCraft aircraft = (IAirCraft)Activator.CreateInstance(type, model, weight, price, attack, defense, hitPoints, new AircraftAssembler());

            return(aircraft);
        }
Exemple #6
0
        public override string Execute()
        {
            string  aircraftType = arguments[0];
            string  model        = arguments[1];
            double  weight       = double.Parse(arguments[2]);
            decimal price        = decimal.Parse(arguments[3]);
            int     attack       = int.Parse(arguments[4]);
            int     defense      = int.Parse(arguments[5]);
            int     hitPoints    = int.Parse(arguments[6]);

            IAirCraft aircraft = aircraftFactory.CreateAirCraft(aircraftType, model, weight, price, attack, defense, hitPoints);

            if (aircraft != null && !aircrafts.ContainsKey(aircraft.Model))
            {
                aircrafts.Add(aircraft.Model, aircraft);
            }

            return(string.Format(GlobalConstants.AircraftSuccessMessage, aircraftType, aircraft.Model));
        }
Exemple #7
0
        public string Battle(IAirCraft attacker, IAirCraft target)
        {
            double attackerWeight    = attacker.TotalWeight;
            long   attackerAttack    = attacker.TotalAttack;
            long   attackerDefense   = attacker.TotalDefense;
            long   attackerHitPoints = attacker.TotalHitPoints;

            double targetWeight    = target.TotalWeight;
            long   targetAttack    = target.TotalAttack;
            long   targetDefense   = target.TotalDefense;
            long   targetHitPoints = target.TotalHitPoints;

            bool isAttackerTurn = true;
            bool isSomeoneDead  = this.IsDead(attackerHitPoints) || this.IsDead(targetHitPoints);

            while (!isSomeoneDead)
            {
                if (isAttackerTurn)
                {
                    targetHitPoints -= (long)Math.Max(0, Math.Ceiling(attackerAttack - (targetDefense + (targetWeight / 2))));
                    isAttackerTurn   = false;
                }
                else
                {
                    attackerHitPoints -= (long)Math.Max(0, Math.Ceiling(targetAttack - (attackerDefense + (attackerWeight / 2))));
                    isAttackerTurn     = true;
                }

                isSomeoneDead = this.IsDead(attackerHitPoints) || this.IsDead(targetHitPoints);
            }

            string result = this.IsDead(attackerHitPoints) ?
                            target.Model :
                            attacker.Model;

            return(result);
        }
Exemple #8
0
 public void DeleteAirCraft(IAirCraft aircraft) => _aircraftlist.Remove(aircraft);
Exemple #9
0
        public static void Run()
        {
            AirPlanes ap = new AirPlanes();

            Console.WriteLine(ap[5]);
            if (ap is IAirCraft)
            {
                Console.WriteLine("Ap is IAirCraft");
            }

            IAirCraft airCraft = ap as IAirCraft;

            ap = airCraft as AirPlanes;
            ap = (AirPlanes)airCraft;

            AirPlanes  ab  = ap as AirPlanes;
            AirPlanes  ab2 = airCraft as AirPlanes;
            ICloneable icl = airCraft as ICloneable;

            if (icl != null)
            {
                Console.WriteLine("IClonable");
            }
            else
            {
                Console.WriteLine("NOT!");
            }


            ClassEnumerable ce = new ClassEnumerable();

            foreach (var t in ce)
            {
                Console.WriteLine(t);
            }
            foreach (var r in ce.GetInt(true))
            {
                Console.WriteLine(r);
            }



            /**********************/
            ClassClonable cc      = new ClassClonable();
            ClassClonable ccClone = cc.Clone() as ClassClonable;

            cc.ShowData();
            ccClone.ShowData();
            cc.ChangeData();


            cc.ShowData();
            ccClone.ShowData();

            ClassClonable deepCopied = cc.DeepCopy();

            Console.WriteLine("Deep Copy");

            deepCopied.ShowData();
            /**********************************/
            ClassComparable        comp1    = new ClassComparable("pokolorowany");
            ClassComparable        comp2    = new ClassComparable("powietrze");
            ClassComparable        comp3    = new ClassComparable("co");
            ClassComparable        comp4    = new ClassComparable("kazdy");
            ClassComparable        comp5    = new ClassComparable("tyl");
            List <ClassComparable> compList = new List <ClassComparable>()
            {
                comp1, comp2, comp3, comp4, comp5
            };

            compList.Sort();
            foreach (var t in compList)
            {
                Console.WriteLine(t.Name);
            }


            compList.Sort(new NamingComparer());
            foreach (var t in compList)
            {
                Console.WriteLine(t.Name);
            }


            comp1.CompareTo(comp2);


            //   if (comp1 > comp2) Console.WriteLine("OK");
        }
Exemple #10
0
 public AirCraft(IAirCraft airCraft)
 {
     _airCraft = airCraft;
 }