Example #1
0
        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("");
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Invoker invoker = new Invoker();        //Command

            Command command = new Command();

            invoker.SetCommand(new OnCommand(command));

            invoker.PressEnter();

            invoker.PressSpace();

            Console.WriteLine("-------------");

            //-------------------------------------

            Player player = new Player(new PlayerIsInFlight());

            player.Come();
            player.Flight();
            player.Stand();
            player.Stand();

            Console.WriteLine("----------------------");

            //-------------------------------------

            Human human = new Human();

            human.Speedup();

            GameHistory game = new GameHistory();

            game.history.Push(human.SaveState());


            human.Speedup();

            human.RestoreState(game.history.Pop());

            human.Speedup();

            Console.WriteLine("-----------------------");

            //---------------------------------------

            Game Game = new Game();

            Hero hero = new Hero("Ilya", Game);

            Game.LVL();

            hero.StopPlay();

            Game.LVL();


            Console.ReadKey();
        }
Example #3
0
        static void Main(string[] args)
        {
            Player player = new Player();
            Hero   elf    = new Hero("Elf");

            player.SetCommand(new JumpCommand(elf));
            player.PressButton();
            player.SetCommand(new FireCommand(elf));
            player.PressButton();
            player.SetCommand(new FireCommand(new Hero("Sniper")));
            player.PressButton();
            Console.WriteLine();


            MyObject myObject = new MyObject(new StandingState());

            myObject.HandleInput("DOWN");
            myObject.HandleInput("DOWN");
            myObject.HandleInput("B");
            myObject.HandleInput("DOWN");
            myObject.HandleInput("DOWN");
            Console.WriteLine();


            player.SetCommand(new FireCommand(elf));
            GameHistory game = new GameHistory();

            game.History.Push(elf.SaveState());
            player.PressButton();
            player.PressButton();
            elf.RestoreState(game.History.Pop());
            Console.WriteLine();


            Subject           subject   = new Subject();
            ConcreteObserverA observerA = new ConcreteObserverA();

            subject.Attach(observerA);
            ConcreteObserverB observerB = new ConcreteObserverB();

            subject.Attach(observerB);
            subject.SomeBusinessLogic();
            subject.Detach(observerB);
            subject.SomeBusinessLogic();
            Console.WriteLine();


            Car auto = new Car(4, "Volvo", new PetrolMove());

            auto.Move();
            auto.Movable = new ElectricMove();
            auto.Move();
            Console.Read();
        }
Example #4
0
        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
            }
        }