示例#1
0
        public Cop CreateHeroe(CompliantHandler handler = null)
        {
            if (_copFactory == null)
            {
                _copFactory = new CopFactory();
            }

            var cop = (Cop)_copFactory.CreateHeroe(handler);

            cop.Tool    = _copFactory.CreateTool();
            cop.Vehicle = _copFactory.CreateVehicle();

            DisplayCommand();
            var success = Int32.TryParse(Console.ReadLine(), out int commandSelected);

            while (!success || commandSelected >= 3)
            {
                Console.Clear();
                Console.WriteLine("Wrong option! :( Please try again.");
                DisplayCommand();
                success = Int32.TryParse(Console.ReadLine(), out commandSelected);
            }

            var strategy = (CommandEnum)commandSelected;

            switch (strategy)
            {
            case CommandEnum.StopRightThere:
                cop.ChangeOrder(new StopRightThere());
                break;

            case CommandEnum.PursueCriminal:
                cop.ChangeOrder(new PursueCriminal());
                break;

            case CommandEnum.RequestBackup:
                cop.ChangeOrder(new RequestBackup());
                break;

            default:
                break;
            }

            return(cop);
        }
示例#2
0
        static void Singleton()
        {
            var copFactory = new CopFactory();
            var quarter    = CreateHeroe(copFactory);
            var quarter2   = CreateHeroe(copFactory);

            Console.WriteLine($"HashCode of quarter 1 is {quarter.GetHashCode()}");
            Console.WriteLine($"HashCode of quarter 2 is {quarter2.GetHashCode()}");

            for (int i = 0; i < 4; i++)
            {
                quarter.AddResponsable(copFactory.CreateHeroe());
                quarter.AddTool(copFactory.CreateTool());
                quarter.AddVehicle(copFactory.CreateVehicle());
            }

            IResponsable b1 = quarter.GetPersonal();
            IResponsable b2 = quarter.GetPersonal();
            IResponsable b3 = quarter.GetPersonal();
            IResponsable b4 = quarter.GetPersonal();
        }