Exemple #1
0
        public MainViewModel()
        {
            var adjustmentFactory = new ResourceAdjustmentFactory();

            _commandFactory = new DelegateCommandFactory();

            _woodCache = new ObservableResourceCache(new ResourceCache(), () =>
            {
                NotifyPropertyChanged(nameof(Wood));
                NotifyPropertyChanged(nameof(Lumbermill));
            });
            Lumbermill = new Lumbermill(_woodCache, adjustmentFactory);

            Increment = _commandFactory.CreateFor(
                () => _woodCache.Apply(adjustmentFactory.CreateIncreaseEqualTo(1)));
            UpgradeLumbermill = _commandFactory.CreateFor(Lumbermill.Upgrade);

            _loop       = new GameLoop(ticksPerSecond: 100);
            _loop.Tick += (tickDuration) =>
            {
                Lumbermill.Generate(tickDuration);
            };
            _loop.Start();

            _woodCache.Apply(adjustmentFactory.CreateIncreaseEqualTo(20));
        }
Exemple #2
0
        public void Generate(decimal generationPeriod)
        {
            var adjustment = _adjustmentFactory.CreateIncreaseEqualTo(GrowthPerSecond * generationPeriod);

            _resourceCache.Apply(adjustment);
        }
 public void Apply(IResourceAdjustment adjustment)
 {
     _resourceCache.Apply(adjustment);
     _notify();
 }