Example #1
0
    private void HandleItemBought(GameObject item)
    {
        FactoryShopApplier factoryShopApplier = item.GetComponent <FactoryShopApplier>();

        if (shopItemBuyer.PlayerHasEnoughScore(factoryShopApplier.cost))
        {
            float totalScore = totalScoreHandler.DecreaseTotalScore(factoryShopApplier.cost);

            totalScoreVisual.SetTotalScoreText(totalScore);

            playerProgressHandler.SaveTotalScore(totalScore);

            BasicFactory basicFactory = boughtItemSpawner.SpawnFactory(factoryShopApplier.gameObject).GetComponent <BasicFactory>();

            basicFactory.GetComponent <FactoryVisualTextSpawner>().SetVisualFactoryObjectsHolder(factoryVisualTextsHolder);

            basicFactory.SetTotalScoreHandler(totalScoreHandler);

            basicFactory.SetTotalScoreVisual(totalScoreVisual);

            basicFactory.SetProductionValues(factoryShopApplier.scorePerUnitOfTime, factoryShopApplier.unitOfTime);

            basicFactory.SetOnUnitOfTimePassedEventHandlers();

            basicFactory.StartFactory();
        }
    }
 public MainWindow()
 {
     var factory = new BasicFactory();
     InitializeComponent();
     _repository = factory.GetRepository(RepositoryType.FILEREPOSITORY);
     _calculator = factory.GetCalculator(CalculatorType.HSERATINGCALCULATOR);
     _repository.GradesChanged += RefreshGrid;
     _repository.IOExceptionOccured += IOExceptionAlert;
     dataGridGrades.ItemsSource = _repository.Grades;
 }
Example #3
0
    public Client(string infix)
    {
        _infix = infix;

        AbstractFactory _factory = new BasicFactory();
        Stack<Command> _postfix = new Stack<Command>();
        new InfixToPostfix(_factory, _postfix, _infix);
        Evaluator _evaluator = new Evaluator(_postfix);
        _result = _evaluator.calculate();
    }
Example #4
0
    public Client(string infix)
    {
        _infix = infix;

        AbstractFactory _factory = new BasicFactory();
        Stack <Command> _postfix = new Stack <Command>();

        new InfixToPostfix(_factory, _postfix, _infix);
        Evaluator _evaluator = new Evaluator(_postfix);

        _result = _evaluator.calculate();
    }
        /**
         * Construct an elevation model given a key for a configuration source and the source's default value.
         *
         * @param key          the key identifying the configuration property in {@link Configuration}.
         * @param defaultValue the default value of the property to use if it's not found in {@link Configuration}.
         *
         * @return a new elevation model configured according to the configuration source.
         */
        public static ElevationModel makeElevationModel(string key, string defaultValue)
        {
            if (key == null)
            {
                String msg = Logging.getMessage("nullValue.KeyIsNull");
                throw new ArgumentException(msg);
            }

            object configSource = Configuration.getStringValue(key, defaultValue);

            return((ElevationModel)BasicFactory.create(AVKey.ELEVATION_MODEL_FACTORY, configSource));
        }
Example #6
0
    static void Main(string[] args)
    {
        IFactory <Basic> notDerived = new BasicFactory();    // from not derived type
        Derived          shape      = new Derived()
        {
            dim1 = 10, dim2 = 20
        };
        double area = new Program().Area(notDerived, shape); // cast! dimension loss

        Console.WriteLine(area);                             // 100 = 10*10
        IFactory <Derived> derived = new DerivedFactory();   //from derived type

        area = new Program().Area(derived, shape);           // no cast, now
        Console.WriteLine(area);                             // 200 = 10*20
        Console.ReadKey();
    }
Example #7
0
        public ShoppingResult Compute()
        {
            TaxCalculator basicCalculator  = BasicFactory.CreateFactory();
            TaxCalculator importCalculator = ImportFactory.CreateFactory();

            var totalBasicTax  = 0.0m;
            var totalImportTax = 0.0m;

            shoppingResult.TotalWithoutTax = preparedCart.Sum(x => x.Price);

            shoppingResult.ItemsBilled = preparedCart;
            shoppingResult.TaxDetail   = new List <TaxDetail>();

            foreach (var item in preparedCart)
            {
                if (!item.IsExempted())
                {
                    totalBasicTax           += basicCalculator.GetTaxAmount(item);
                    TaxDetail.BasicTaxAmount = basicCalculator.GetTaxAmount(item);
                }
                else
                {
                    TaxDetail.BasicTaxAmount = 0.0m;
                }

                if (item.IsImported)
                {
                    totalImportTax           += importCalculator.GetTaxAmount(item);
                    TaxDetail.ImportTaxAmount = importCalculator.GetTaxAmount(item);
                }
                shoppingResult.TaxDetail.Add(TaxDetail);
            }

            shoppingResult.TotalImportTax = totalImportTax;
            shoppingResult.TotalSalesTax  = totalBasicTax;
            shoppingResult.TotalTax       = totalImportTax + totalBasicTax;
            shoppingResult.Total          = shoppingResult.TotalWithoutTax + totalImportTax + totalBasicTax;

            return(shoppingResult);
        }
        public static ISector CreateDecorator(ISector sector, DecoratorTypeEnum type, int value = 0)
        {
            FactoryDecorator sectorFactory = null;

            switch (type)
            {
            case DecoratorTypeEnum.BigTrees:
                sectorFactory = new BigTreesFactory(sector);
                break;

            case DecoratorTypeEnum.DryGrass:
                sectorFactory = new DryGrassFactory(sector);
                break;

            case DecoratorTypeEnum.HotDay:
                sectorFactory = new HotDayFactory(sector, value);
                break;

            case DecoratorTypeEnum.RainingDay:
                sectorFactory = new RainingDayFactory(sector, value);
                break;

            case DecoratorTypeEnum.ScaredPeople:
                var scaredPeople = GenerateRandomValue.GetRandom(0, 6);
                sectorFactory = new ScaredPeopleFactory(sector, scaredPeople);
                break;

            case DecoratorTypeEnum.WindyDay:
                sectorFactory = new WindyDayFactory(sector, value);
                break;

            case DecoratorTypeEnum.Basic:
                sectorFactory = new BasicFactory(sector);
                break;
            }

            return(sectorFactory.CreateSector());
        }
Example #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("\n************************ Singleton Pattern *************************** ");
            // example of using singleton
            Singleton.Instance.TestMethod();

            Console.WriteLine("\n************************ Factory Pattern *************************** ");

            var factory = new BasicFactory();
            var block   = factory.CreateBlock();

            Console.WriteLine("\nCreated with BasicFactory type: " + block.GetName());

            var factory2 = new SegmentedFactory();
            var block2   = factory2.CreateBlock();

            Console.WriteLine("\nCreated with SegmentedFactory type: " + block2.GetName());

            var generalFactory = new Factory();
            var block3         = generalFactory.CreateBlock(Factory.Type.Basic);
            var block4         = generalFactory.CreateBlock(Factory.Type.Segmented);

            Console.WriteLine("\nCreated with Factory block3: " + block3.GetName() + " block4: " + block4.GetName());

            Console.WriteLine("\n************************ Adapter Pattern *************************** ");

            IAdapter adapter1 = new AdapterUI1(new UISystem1());
            IAdapter adapter2 = new AdapterUI2(new UISystem2());

            adapter1.IncreaseProgress();
            adapter1.IncreaseHealth();
            adapter2.IncreaseProgress();
            adapter2.IncreaseHealth();
            Console.WriteLine("For additional test press arrow up!");

            Console.WriteLine("\n************************ Facade Pattern *************************** ");

            //Facade
            Mortgage mortgage = new Mortgage();

            //Evaluate mortgage eligibility for customer
            Customer customer = new Customer("Marko Milovanovic");
            bool     eligible = mortgage.IsEligible(customer, 60000);

            Console.WriteLine("\n" + customer.Name + " has been " + (eligible ? "Approved" : "Rejected"));

            Console.WriteLine("\n************************ Chain Of Responsibility Pattern *************************** ");
            var coinsShopHandler   = new BuyCoinsHandler();
            var costumeShopHandler = new BuyCostumeHandler();
            var packShopHandler    = new BuyPackHandler();

            coinsShopHandler.SetSuccessor(costumeShopHandler);
            costumeShopHandler.SetSuccessor(packShopHandler);

            coinsShopHandler.HandleRequest(ShopItemType.Costume);

            Console.WriteLine("\n************************ Observer Pattern *************************** ");
            Game.Instance.Score++;
            Console.WriteLine("For additional testing press 'I' . We have UIController and AchievementController as observers!");

            ConsoleKeyInfo keyinfo;

            do
            {
                keyinfo = Console.ReadKey(true);
                if (keyinfo.Key == ConsoleKey.UpArrow)
                {
                    Console.WriteLine("\nAdapter Pattern testing:");
                    adapter1.IncreaseProgress();
                    adapter1.IncreaseHealth();
                    adapter2.IncreaseProgress();
                    adapter2.IncreaseHealth();
                }

                if (keyinfo.Key == ConsoleKey.I)
                {
                    Console.WriteLine("\nObserver Pattern testing:");
                    Game.Instance.Score++;
                }
            }while (keyinfo.Key != ConsoleKey.Spacebar);
        }
 /**
  * Creates a shapefile layer described by an XML layer description. This delegates layer construction to the factory
  * class associated with the configuration key "gov.nasa.worldwind.avkey.ShapefileLayerFactory".
  *
  * @param domElement the XML element describing the layer to create. The element must contain the shapefile
  *                   location, and may contain elements specifying shapefile attribute mappings, shape attributes to
  *                   assign to created shapes, and layer properties.
  * @param parameters     any parameters to apply when creating the layer.
  *
  * @return a new layer
  */
 protected Layer createShapefileLayer(Element domElement, AVList parameters)
 {
     return((Layer)BasicFactory.create(AVKey.SHAPEFILE_LAYER_FACTORY, domElement, parameters));
 }