示例#1
0
文件: Program.cs 项目: oxugen/labs
        static void Main(string[] args)
        {
            Hunter h1 = new Hunter();

            Console.WriteLine(h1.ToString());
            Shaman s1 = new Shaman();

            Console.WriteLine(s1.ToString());

            IActions[] actionsArr = new IActions[4];
            actionsArr[0] = h1;
            actionsArr[1] = s1;
            actionsArr[2] = new Fighter();
            actionsArr[3] = new Marksman();
            Printer p1 = new Printer();

            foreach (IActions i in actionsArr)
            {
                p1.IAmPrinting(i);
            }

            IActions ref1 = h1 as IActions;

            Console.WriteLine(h1 is IActions);
            Console.WriteLine(ref1 is IActions);
            Console.WriteLine((ref1 != null));
            Test     test1 = new Test();
            IActions ref2  = test1 as IActions;

            Console.WriteLine((ref2 != null));
            A a = new A(); B b = new B(); b.m(3, 4);
        }
示例#2
0
        static void Main(string[] args)
        {
            try
            {
                Hunter h1 = new Hunter(3);
                //Hunter h2 = new Hunter(-3);

                Shaman s1       = new Shaman();
                Army   armyCol1 = new Army();
                armyCol1.Add(h1);
                armyCol1.Add(s1);
                Fighter  f1 = new Fighter(3);
                Marksman m1 = new Marksman(8);
                armyCol1.Add(f1);
                armyCol1.Add(m1);
                armyCol1.Add(f1);
                armyCol1.Write();
                armyCol1.Delete(2);


                armyCol1.Add(null);
                Console.WriteLine(armyCol1[10]);
                armyCol1.Delete(20);

                Console.WriteLine();
                armyCol1.Write();
                Console.WriteLine(armyCol1.GetAttack());
                Console.WriteLine();
                Console.WriteLine(ArmyController.GetTheStrongest(armyCol1));
                Console.WriteLine();
                ArmyController.Sort(armyCol1);
                armyCol1.Write();
            }
            catch (ZeroAttackInputException e)
            {
                Console.WriteLine("Исключение " + e.Message + "\n" + "Неверное значение: " + e.wrongValue.ToString());
                Console.WriteLine($"Метод: { e.TargetSite}");
            }
            catch (AttackInputException e)
            {
                Console.WriteLine("Исключение " + e.Message + "\n" + "Неверное значение: " + e.wrongValue.ToString());
                Console.WriteLine($"Метод: { e.TargetSite}");
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("Исключение " + e.Message);
                Console.WriteLine($"Метод: { e.TargetSite}");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine($"Метод: { e.TargetSite}");
            }
            finally
            {
                Console.WriteLine("\nКонец работы программы");
            }
        }