Exemple #1
0
        public HudScene(ScreenSpace screen, NumberFactory numberFactory)
        {
            var view   = screen.Viewport;
            var center = view.Width / 2f;
            var left   = view.Left;
            var top    = view.Top;
            var right  = view.Right;

            pointsNumber = numberFactory.CreateNumber(this, left, top, 0.05f, Alignment.Left, 0,
                                                      DefaultColors.Gray);
            levelCaption = new Sprite("LevelCaption",
                                      Rectangle.FromCenter(center, top + 0.02f, 0.07f, 0.03f));
            levelCaption.Color = DefaultColors.Yellow;
            // ReSharper disable DoNotCallOverridableMethodsInConstructor
            Add(levelCaption);
            levelNumber = numberFactory.CreateNumber(this, center, levelCaption.DrawArea.Bottom, 0.022f,
                                                     Alignment.Center, 2, DefaultColors.Gray);
            var offsets = new[, ] {
                { 0.108f, 0.025f }, { 0.083f, 0.033f }, { 0.05f, 0.05f }
            };

            errorIcons = new Sprite[3];
            for (int i = 0; i < errorIcons.Length; i++)
            {
                Add(errorIcons[i] = new Sprite("ErrorIcon",
                                               new Rectangle(right - offsets[i, 0], top, offsets[i, 1], offsets[i, 1])));
            }
            foreach (var control in Controls.FindAll(x => x is Sprite))
            {
                control.RenderLayer = (int)GameRenderLayer.Hud;
            }
        }
Exemple #2
0
        public bool IsIdentifier()
        {
            if (_builder.IsEmpty)
            {
                return(false);
            }

            var body = _builder.Body;

            if (!VariableFactory.CheckSymbol(body[0]))
            {
                return(false);
            }

            for (var i = 1; i < body.Length; i++)
            {
                if (!VariableFactory.CheckSymbol(body[i]) &&
                    (!NumberFactory.CheckSymbol(body[i]) || body[i].Equals(NumberFactory.DecimalSeparator)))
                {
                    return(false);
                }
            }

            return(true);
        }
        public void Create1000(string romanNumber, int result)
        {
            var numberFactory = new NumberFactory();

            var number = numberFactory.Create(romanNumber);

            Assert.IsNotNull(number);
            Assert.AreEqual(result, number.Value);
        }
        public void CreateNumbers(char character, int result)
        {
            var numberFactory = new NumberFactory();

            var number = numberFactory.Create(character);

            Assert.IsNotNull(number);
            Assert.AreEqual(result, number.Value);
        }
        public void Works_with_not_matching_0_as_data_source()
        {
            var factoryProviders = GetFactoryProvidersSource(new DefaultFactoryProvider<NumberFactory>());
            var dataSource = GetDataSource(0);

            var factory = new NumberFactory { FactoryProvidersSource = factoryProviders, DataSource = dataSource };
            var enumerator = factory.GetEnumerator();

            Assert(enumerator, "0");
            IsFalse(enumerator.MoveNext());
        }
        public void Works_with_expected_1_and_data_source_0_then_1()
        {
            var factoryProviders = GetFactoryProvidersSource(new DefaultFactoryProvider<NumberFactory>());
            var dataSource = GetDataSource(0, 1);

            var factory = new NumberFactory { FactoryProvidersSource = factoryProviders, DataSource = dataSource };
            var enumerator = factory.GetEnumerator();

            Assert(enumerator, "0");
            Assert(enumerator, "1");
            IsFalse(enumerator.MoveNext());
        }
        public void BeAbleToGenRandomNum()
        {
            int forcedRandomNum = 5;
            var mockGenerator   = new Mock <IRandomGenerator>();

            mockGenerator.Setup(generator => generator.Generate()).Returns(forcedRandomNum);
            _numberFactory = new NumberFactory(mockGenerator.Object);

            // Determining 'random' number generated is returned
            _numberFactory.GenerateRandomNumber().ShouldBe(forcedRandomNum);

            // Testing to make sure 'random.Next' was called
            mockGenerator.Verify(generator => generator.Generate(), Times.Once());
        }
Exemple #8
0
 public Match(ScreenSpace screen, NumberFactory numberFactory, LogoFactory logoFactory)
     : base(Rectangle.Zero)
 {
     this.screen      = screen;
     this.logoFactory = logoFactory;
     hud   = new HudScene(screen, numberFactory);
     pause = new PausePage(screen);
     pause.Hide();
     Slice      = new Slice();
     PointsTips = new List <PointsTip>();
     ErrorFlags = new List <ErrorFlag>();
     HideScore();
     screen.ViewportSizeChanged += RefreshSize;
     RefreshSize();
 }
Exemple #9
0
        private static SymbolType GetSymbolType(char value)
        {
            if (NumberFactory.CheckSymbol(value))
            {
                return(SymbolType.Number);
            }

            if (OperatorFactory.CheckSymbol(value))
            {
                return(SymbolType.Operator);
            }

            if (VariableFactory.CheckSymbol(value))
            {
                return(SymbolType.Identifier);
            }

            return(SymbolType.Undefined);
        }
Exemple #10
0
        /// <inheritdoc/>
        public string NextString(int length, params char[] chars)
        {
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length), $"{nameof(length)} must greater than 0.");
            }
            if (chars is null || chars.Length <= 0)
            {
                throw new ArgumentNullException(nameof(chars), $"{nameof(chars)} must have at least 1 element.");
            }

            double[] doubles = NumberFactory.MakeDoubleArray(NextBytes(length * sizeof(ulong)));
            var      builder = new StringBuilder(length);

            for (var i = 0; i < length; i++)
            {
                builder.Append(chars[(int)(doubles[i] * chars.Length)]);
            }

            return(builder.ToString());
        }
Exemple #11
0
        public override InterpreterState MoveToNextState(Symbol symbol, ILexemesStack stack, ExecutorContext context)
        {
            switch (symbol.Type)
            {
            case SymbolType.Number:
                _numberBuilder.Append(symbol);
                return(this);

            case SymbolType.Identifier:
                return(new ErrorState(symbol));

            case SymbolType.Operator:
                var @operator = OperatorFactory.CreateOperator(symbol);
                var number    = NumberFactory.CreateNumber(_numberBuilder);

                stack.Push(number);
                stack.Push(@operator);

                switch (@operator)
                {
                case OpeningBracket _:
                case AssignmentOperator _:
                case CommaOperator _:
                    return(new ErrorState(symbol));

                case ClosingBracket _:
                    return(new ClosingBracketOperatorState());

                default:
                    return(new BinaryOperatorState());
                }

            default:
                return(new ErrorState(symbol));
            }
        }
 private void OnNumberTypeChanged(DependencyPropertyChangedEventArgs e)
 {
     _number = NumberFactory.Create((NumberType)e.NewValue);
     _number.Initialize(Number, Minimum, Maximum, Step, DefaultNumber, InputCulture, PredefinesCulture);
 }
Exemple #13
0
 /// <inheritdoc/>
 public double NextDouble()
 => NumberFactory.MakeDouble(NextULong());
Exemple #14
0
 /// <inheritdoc/>
 public float NextFloat()
 => NumberFactory.MakeFloat(NextUInt());
Exemple #15
0
 /// <inheritdoc/>
 public ulong NextULong()
 => NumberFactory.MakeULong(NextBytes(sizeof(ulong)));
Exemple #16
0
 /// <inheritdoc/>
 public uint NextUInt()
 => NumberFactory.MakeUInt(NextBytes(sizeof(uint)));
Exemple #17
0
 /// <inheritdoc/>
 public ushort NextUShort()
 => NumberFactory.MakeUShort(NextBytes(sizeof(ushort)));
Exemple #18
0
 public GameLogic(ScreenSpace screen, NumberFactory numberFactory)
 {
     this.numberFactory = numberFactory;
     this.screen        = screen;
     waveTimeout        = GameSettings.InitialWaveTimeout;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DW.WPFToolkit.Controls.NumberBox" /> class.
 /// </summary>
 public NumberBox()
 {
     _number = NumberFactory.Create(NumberType);
 }
 public NumberFactoryShould()
 {
     _numberFactory = new NumberFactory();
 }