Example #1
0
        /// <summary>
        /// Конструктор батальона
        /// </summary>
        /// <param name="count">Колличество танков</param>
        public TankBattalion(int count)
        {
            RussianFactory russianFactory = new RussianFactory();
            Random         r = new Random();

            for (int i = 0; i < count; i++)
            {
                if (r.Next(2) == 0)
                {
                    Tank tank = new Tank(russianFactory, TypeOfArmor.Dynamic, TypeOfGun.Artillery, TypeOfEngine.Gasturbine);

                    tanks.Add((T)tank);
                }
                else
                {
                    Tank tank = new Tank(russianFactory, TypeOfArmor.Composite, TypeOfGun.Artillery, TypeOfEngine.Gasturbine);

                    tanks.Add((T)tank);
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            RussianFactory russianFactory = new RussianFactory();

            TankBattalion <Tank> tankBattalion = new TankBattalion <Tank>(2);

            var xmlSer  = new XmlSerialization <Tank>();
            var jsonSer = new JSONSerialization <Tank>();
            var binSer  = new BinarySerialization <Tank>();

            xmlSer.Serialize(tankBattalion, "xml1.xml");
            jsonSer.Serialize(tankBattalion, "jsonTanks.json");
            binSer.Serialize(tankBattalion, "binary.dat");

            TankBattalion <Tank> tankBattalion1 = new TankBattalion <Tank>(0);
            TankBattalion <Tank> tankBattalion2 = new TankBattalion <Tank>(0);
            TankBattalion <Tank> tankBattalion3 = new TankBattalion <Tank>(0);

            tankBattalion1 = xmlSer.Deserialize("xml1.xml");
            tankBattalion2 = binSer.Deserialize("binary.dat");
            tankBattalion3 = jsonSer.Deserialize("jsonTanks.json");

            foreach (Tank t in tankBattalion)
            {
                t.GetStatus();
                Console.WriteLine("\n");
            }

            //Console.WriteLine("______");

            //foreach (Tank t in tankBattalion1)
            //{
            //    t.GetStatus();
            //}

            Console.WriteLine("______");

            foreach (Tank t in tankBattalion3)
            {
                t.GetStatus();
                Console.WriteLine("\n");
            }

            //Tank tank = new Tank(russianFactory, TypeOfArmor.Dynamic, TypeOfGun.Artillery, TypeOfEngine.Gasturbine);
            //Tank tank1 = Tank.CreateFromFile("tank.txt");

            //var consLogger = new ConsoleLogger<ITank<IComponent>>(tank);
            //var fileLogger = new FileLogger<ITank<IComponent>>(tank1, "log1.txt");

            //consLogger.Log += LogOnLog;
            //fileLogger.Log += LogOnLog;

            ////tank.Move();
            ////tank.Shot(tank1);

            //// не сработает, так как нет цели, пользовательское исключение
            //try
            //{
            //    tank1.Shot(null);
            //}
            //catch (UserException error)
            //{
            //    ExceptionsLogger.LogUserException(error);
            //}
            //catch (Exception error)
            //{
            //    ExceptionsLogger.LogSystemException(error);
            //}

            //// не сработает, такого элемента нет, системное исключение
            //try
            //{
            //    tank1.Shot(tankBattalion[0]);
            //}
            //catch (UserException error)
            //{
            //    ExceptionsLogger.LogUserException(error);
            //}
            //catch (Exception error)
            //{
            //    ExceptionsLogger.LogSystemException(error);
            //}
            ////tank.Shot(tank1);
            ////tank1.Move();
            ////tank1.Shot(tank);
            ////tank.Move();
            ////tank.Aimp(tank1.armor.GetHealth);

            //tankBattalion.Add(tank);
            //tankBattalion.Add(tank1);
            //tankBattalion.Add((Tank)tank.Clone());
            //tank.gun.Destroy();


            //Task t = tankBattalion.AsyncSort();
            //t.Wait();



            Console.ReadLine();
        }
Example #3
0
        public static Tank CreateFromFile(string path)
        {
            var info = File.ReadAllLines(path);

            TypeOfArmor  armorType   = TypeOfArmor.Composite;
            TypeOfEngine engineType  = TypeOfEngine.Gasturbine;
            TypeOfGun    gunType     = TypeOfGun.Tank;
            Factory      factoryType = new RussianFactory();

            try
            {
                switch (info[0])
                {
                case "Russian":
                {
                    factoryType = new RussianFactory();
                    break;
                }

                case "American":
                {
                    factoryType = new AmericanFactory();
                    break;
                }
                }
                switch (info[1])
                {
                case "Artillery":
                {
                    gunType = TypeOfGun.Artillery;
                    break;
                }

                case "Tank":
                {
                    gunType = TypeOfGun.Tank;
                    break;
                }
                }
                switch (info[2])
                {
                case "Dynamic":
                {
                    armorType = TypeOfArmor.Dynamic;
                    break;
                }

                case "Composite":
                {
                    armorType = TypeOfArmor.Composite;
                    break;
                }
                }
                switch (info[3])
                {
                case "Diesel":
                {
                    engineType = TypeOfEngine.Diesel;
                    break;
                }

                case "Gasturbine":
                {
                    engineType = TypeOfEngine.Gasturbine;
                    break;
                }
                }
            }
            catch (FormatException) { throw new FileFormatException("Входной файл имел неверный формат"); }

            return(new Tank(factoryType, armorType, gunType, engineType));
        }