コード例 #1
0
ファイル: Program.cs プロジェクト: overkektus/C-sharp_labs
        static void Main(string[] args)
        {
            Hunter hunter1 = new Hunter();

            Console.WriteLine(hunter1.ToString());
            hunter1.WriteToFile();
            hunter1 += 3;
            hunter1.Go(hunter1);
            Console.WriteLine(hunter1.ToString());
            Console.WriteLine("hunter1.GetHashCode() - " + hunter1.GetHashCode() + "\n");

            Hunter hunter2 = new Hunter();

            Console.WriteLine(hunter2.ToString() + "\n");

            Console.WriteLine("hunter1 > hunter2?");
            Console.WriteLine(hunter1 > hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 < hunter2?");
            Console.WriteLine(hunter1 < hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 == hunter2?");
            Console.WriteLine(hunter1 == hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 != hunter2?");
            Console.WriteLine(hunter1 != hunter2);
            Console.WriteLine();

            Shaman shaman = new Shaman();

            Console.WriteLine(shaman.ToString());
            shaman += 2;
            Console.WriteLine(shaman.ToString() + "\n");

            try
            {
                Hunter hunter3 = new Hunter();
                hunter3.HP = -30;
            }
            catch (InvalidParam exp)
            {
                Console.WriteLine(new String('!', 53));
                Console.WriteLine(exp.What());
            }
            finally
            {
                Console.WriteLine("\n----------Блок finally");

                GameHistory game = new GameHistory();

                Console.WriteLine(shaman.ToString() + "\n");

                game.History.Push(shaman.SaveState());
                shaman.RestoreState(game.History.Pop());
                Console.WriteLine("");
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: overkektus/C-sharp_labs
        static void Main(string[] args)
        {
            Hunter hunter1 = new Hunter();

            Console.WriteLine(hunter1.ToString());
            hunter1.WriteToFile();
            hunter1 += 3;
            hunter1.Go(hunter1);
            Console.WriteLine(hunter1.ToString());
            Console.WriteLine("hunter1.GetHashCode() - " + hunter1.GetHashCode() + "\n");

            Hunter hunter2 = new Hunter();

            Console.WriteLine(hunter2.ToString() + "\n");

            Console.WriteLine("hunter1 > hunter2?");
            Console.WriteLine(hunter1 > hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 < hunter2?");
            Console.WriteLine(hunter1 < hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 == hunter2?");
            Console.WriteLine(hunter1 == hunter2);
            Console.WriteLine();

            Console.WriteLine("hunter1 != hunter2?");
            Console.WriteLine(hunter1 != hunter2);
            Console.WriteLine();

            Shaman shaman = new Shaman();

            Console.WriteLine(shaman.ToString());
            shaman += 2;
            Console.WriteLine(shaman.ToString() + "\n");

            try
            {
                Hunter hunter3 = new Hunter();
                hunter3.HP = -30;
            }
            catch (InvalidParam exp)
            {
                Console.WriteLine(new String('!', 53));
                Console.WriteLine(exp.What());
            }
            finally
            {
                Console.WriteLine("\n----------Блок finally");

                GameHistory gameHistory = new GameHistory();

                Console.WriteLine(shaman.ToString() + "\n");

                gameHistory.History.Push(shaman.SaveState());
                shaman.RestoreState(gameHistory.History.Pop());
                Console.WriteLine("");


                Game game = new Game();

                game.Attacked += Attack; //добавляем обработчик события
                Console.WriteLine("\t~~~~~Событие Attacked~~~~~");
                Console.WriteLine(hunter1.ToString());
                Console.WriteLine(shaman.ToString());
                Console.ReadLine();

                game.Battle(hunter1, shaman);
                Console.WriteLine(hunter1.ToString());
                Console.WriteLine(shaman.ToString());
                Console.ReadLine();

                game.Treated += Treat;
                Console.WriteLine("\t~~~~~Событие Treated~~~~~");
                Console.WriteLine(hunter2.ToString());
                Console.ReadLine();

                game.Treatment(shaman, hunter2);
                Console.WriteLine(hunter2);

                Console.ReadLine();

                Reflector.Write("Fighter");                                        //a
                Reflector.WriteAllPublicMethods("IAtack");                         //b
                Reflector.WriteFieldAndProperties("Memento");                      //c
                Reflector.WriteImplementedInterfaces("Hunter");                    //d
                Reflector.WriteNameOfMethodsWithSpecifiedType("Game", "Fighter");  //e
                Reflector.ReadArgsMethodFromFile("lab3.MyClass", "Color_Message"); //f
            }
        }