Ejemplo n.º 1
0
        public void ShouldReturnAllComponentsMatchingPredicate()
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            var customFoo = new FooComponent { Test = "NewFoo" };
            var barComp = new BarComponent();
            var customBar = new BarComponent { Test = "NewBar" };
            state.AddComponent(fooComp);
            state.AddComponent(customFoo);
            state.AddComponent(barComp);
            state.AddComponent(customBar);

            // We have to do some null checking, as we have both Foo and Bar components
            // in the game state.

            Assert.AreEqual(state.GetAllComponents(c =>
            {
                var f = c as FooComponent;
                return f != null && f.Test == "NewFoo";
            }).Count(), 1);

            Assert.IsEmpty(state.GetAllComponents(c =>
            {
                var f = c as FooComponent;
                return f != null && f.Test == "NewBar";
            }));
        }
Ejemplo n.º 2
0
 public void ShouldReturnAllComponentsOfType()
 {
     var state = new TestState();
     var fooComp = new FooComponent();
     var customFoo = new FooComponent { Test = "NewFoo" };
     var barComp = new BarComponent();
     var customBar = new BarComponent { Test = "NewBar" };
     state.AddComponent(fooComp);
     state.AddComponent(customFoo);
     state.AddComponent(barComp);
     state.AddComponent(customBar);
     Assert.AreEqual(state.GetAllComponents(typeof(FooComponent)).Count(), 2);
 }
Ejemplo n.º 3
0
        public Ship(string spriteName, EntityType type) : base(spriteName, type)
        {
            switch (type)
            {
            case EntityType.PLAYER:
                movementComponent = new PlayerMovementComponent();
                break;

            case EntityType.COMPUTER:
                movementComponent = new AIMovementComponent();
                break;
            }

            collisionComponent = new PerPixelCollisionComponent(this);
            _barComponent      = new BarComponent(position, new Vector2(-100, 200), new Vector2(200, 50), _maxHealth);
        }
Ejemplo n.º 4
0
        public static DataSeriesType GetDataSeries(this MarketSeries marketSeries, BarComponent source)
        {
            switch (source)
            {
            case BarComponent.Open:
                return(marketSeries.Open);

            case BarComponent.High:
                return(marketSeries.High);

            case BarComponent.Low:
                return(marketSeries.Low);

            case BarComponent.Close:
                return(marketSeries.Close);

            default:
                throw new ArgumentException();
            }
        }
Ejemplo n.º 5
0
        protected void AddGraph()
        {
            var gaugeBlock = new BarComponent(pid)
            {
                Width       = this.Width - (borderEdgePadding * 2),
                Height      = GetGaugeHeight() - (borderEdgePadding * 2),
                Orientation = Orientation.Horizontal,
            };
            var border = new Border()
            {
                BorderThickness = new System.Windows.Thickness(borderEdgePadding, borderEdgePadding, borderEdgePadding, borderEdgePadding),
                Background      = new SolidColorBrush(Colors.Black),
            };

            border.Child = gaugeBlock;
            Children.Add(border);
            SetLeft(border, 0);
            SetTop(border, Height - gaugeBlock.Height - (borderEdgePadding * 2));
            gaugeBlock.Draw();
        }
        private void AddGraph()
        {
            BarComponent barGraph = new BarComponent(pid)
            {
                Width           = ContentPanel.Width,
                Height          = GetGaugeHeight() - 2,
                Orientation     = Orientation.Vertical,
                EmptyColor      = new SolidColorBrush(gaugeSettings.BackgroundColor),
                SolidValueColor = new SolidColorBrush(GraphColor)
            };

            ContentPanel.Children.Add(barGraph);
            barGraph.Draw();

            /*ContentPanel.Children.Add(
             *  new Line()
             *  {
             *      StrokeThickness = 2,
             *      Stroke = new SolidColorBrush(GraphColor),
             *      X1 = X2 = Y1 = Y2 =
             *  }
             * );*/
        }
Ejemplo n.º 7
0
        public IMovingAverageIndicator MovingAverage(MovingAverageType movingAverageType, int periods, BarComponent indicatorBarComponent = BarComponent.Close, DataSeries indicatorBarSource = null)
        {
            switch (movingAverageType)
            {
            case MovingAverageType.Simple:
                return(new SimpleMovingAverage(new TSimpleMovingAverage
                {
                    TimeFrame = owner.TimeFrame,
                    Symbol = owner.Symbol.Code,
                    Periods = periods,
                    IndicatorBarComponent = indicatorBarComponent,
                    IndicatorBarSource = indicatorBarSource,
                }));

            case MovingAverageType.Exponential:
                return(new ExponentialMovingAverage(new TExponentialMovingAverage
                {
                    TimeFrame = owner.TimeFrame,
                    Symbol = owner.Symbol.Code,
                    Periods = periods,
                    IndicatorBarComponent = indicatorBarComponent,
                    IndicatorBarSource = indicatorBarSource,
                }));

            case MovingAverageType.TimeSeries:
                return(new TimeSeriesMovingAverage(new TTimeSeriesMovingAverage
                {
                    TimeFrame = owner.TimeFrame,
                    Symbol = owner.Symbol.Code,
                    Periods = periods,
                    IndicatorBarComponent = indicatorBarComponent,
                    IndicatorBarSource = indicatorBarSource,
                }));

            case MovingAverageType.Triangular:
                return(new TriangleMovingAverage(new TTriangleMovingAverage
                {
                    TimeFrame = owner.TimeFrame,
                    Symbol = owner.Symbol.Code,
                    Periods = periods,
                    IndicatorBarComponent = indicatorBarComponent,
                    IndicatorBarSource = indicatorBarSource,
                }));

            case MovingAverageType.VIDYA:
                return(new VidyaMovingAverage(new TVidyaMovingAverage
                {
                    TimeFrame = owner.TimeFrame,
                    Symbol = owner.Symbol.Code,
                    Periods = periods,
                    IndicatorBarComponent = indicatorBarComponent,
                    IndicatorBarSource = indicatorBarSource,
                }));

            case MovingAverageType.Weighted:
                return(new WeightedMovingAverage(new TWeightedMovingAverage
                {
                    TimeFrame = owner.TimeFrame,
                    Symbol = owner.Symbol.Code,
                    Periods = periods,
                    IndicatorBarComponent = indicatorBarComponent,
                    IndicatorBarSource = indicatorBarSource,
                }));

            case MovingAverageType.WilderSmoothing:
                return(new WilderSmoothingMovingAverage(new TWilderSmoothingMovingAverage
                {
                    TimeFrame = owner.TimeFrame,
                    Symbol = owner.Symbol.Code,
                    Periods = periods,
                    IndicatorBarComponent = indicatorBarComponent,
                    IndicatorBarSource = indicatorBarSource,
                }));

            default:
                throw new NotImplementedException("Only SimpleMovingAverage currently supported");
            }
        }
Ejemplo n.º 8
0
        [Test]
        public void ShouldReturnComponentOfType()
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            var customFoo = new FooComponent { Test = "NewFoo" };
            state.AddComponent(fooComp);
            state.AddComponent(customFoo);

            Assert.IsInstanceOf<FooComponent>(state.GetComponent(typeof(FooComponent)));
        }

        [Test]
Ejemplo n.º 9
0
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            var fooComp2 = new FooComponent();
            state.AddComponent(fooComp);
            Assert.True(state.HasComponent(fooComp));
            Assert.False(state.HasComponent(fooComp2));
        }

        [Test]
        public void ShouldHaveComponentOfType()
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            state.AddComponent(fooComp);
            Assert.True(state.HasComponent(typeof(FooComponent)));
            Assert.False(state.HasComponent(typeof(BarComponent)));
        }

        [Test]
        public void ShouldHaveComponentMatchingPredicate()
        {
            var state = new TestState();
            var fooComp = new FooComponent();
            state.AddComponent(fooComp);
            Assert.True(state.HasComponent(c => ((FooComponent)c).Test == "Foo"));
            Assert.False(state.HasComponent(c => ((FooComponent)c).Test == "Bar"));