示例#1
0
        public void ShouldWorkForBasicValue()
        {
            var blk = new ValueBlock(2);
            Assert.AreEqual("[2]", blk.GetMessage());

            blk.WithType();
            Assert.AreEqual("[2] of type: [int]", blk.GetMessage());
        }
示例#2
0
    /// <summary>
    /// Passes the parameter with block
    /// </summary>
    /// <param name="inputIndex">Input index. 0 ~ 3</param>
    /// <param name="valueBlock">Value block. Passed Parameter Value Block</param>
    public void PassParameter(int inputIndex, ValueBlock valueBlock)
    {
        PropertyInfo parameterPropertyInfo = GetParameterPropertyInfo(inputIndex);

        if (parameterPropertyInfo != null)
        {
            parameterPropertyInfo.SetValue(this, valueBlock);
        }
    }
示例#3
0
        public void ShouldWorkForMatrices()
        {
            var matrix = new[, ] {
                { 1, 2, 3 }, { 4, 5, 6 }
            };
            var blk = new ValueBlock(matrix);

            Assert.AreEqual("[{{1, 2, 3}, {4, 5, 6}}]", blk.GetMessage());
        }
示例#4
0
        public void ShouldWorkForEnumeration()
        {
            var list = new [] { "a", "b", "c" };
            var blk  = new ValueBlock(list);

            Assert.AreEqual("[{\"a\", \"b\", \"c\"}]", blk.GetMessage());

            Assert.Throws <NotImplementedException>(() => blk.WithEnumerableCount(list.GetLength(0)));
        }
示例#5
0
        public void ShouldWorkForBasicValue()
        {
            var blk = new ValueBlock(2);

            Assert.AreEqual("[2]", blk.GetMessage());

            blk.WithType();
            Assert.AreEqual("[2] of type: [int]", blk.GetMessage());
        }
示例#6
0
        public void ShouldWorkForEnumeration()
        {
            var list = new []{ "a", "b", "c" };
            var blk = new ValueBlock(list);

            Assert.AreEqual("[\"a\", \"b\", \"c\"]", blk.GetMessage());

            blk.WithEnumerableCount(list.GetLength(0));
            Assert.AreEqual("[\"a\", \"b\", \"c\"] (3 items)", blk.GetMessage());
        }
示例#7
0
        public void ShouldWorkForEnumeration()
        {
            var list = new [] { "a", "b", "c" };
            var blk  = new ValueBlock(list);

            Assert.AreEqual("[\"a\", \"b\", \"c\"]", blk.GetMessage());

            blk.WithEnumerableCount(list.GetLength(0));
            Assert.AreEqual("[\"a\", \"b\", \"c\"] (3 items)", blk.GetMessage());
        }
示例#8
0
        void Window_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (WillTriggerManual)
            {
                IsDragging = false;
                ValueBlock.TriggerEdit();
                WillTriggerManual      = false;
                IsPerformingManualEdit = true;

                return;
            }

            ValueBlock_MouseUp(sender, e);
        }
示例#9
0
    /// <summary>
    /// Tries the get parameter value.
    /// </summary>
    /// <returns><c>true</c>, when parameter exist and return parameter, <c>false</c> otherwise.</returns>
    /// <param name="inputIndex">Input index. 1 ~ 4</param>
    /// <param name="parameterValue">Parameter value.</param>
    public bool TryGetParameterValue(int inputIndex, out ValueBlock parameterValue)
    {
        PropertyInfo parameterPropertyInfo = GetParameterPropertyInfo(inputIndex);

        if (parameterPropertyInfo != null)
        {
            parameterValue = parameterPropertyInfo.GetValue(this) as ValueBlock;
            return(true);
        }
        else
        {
            parameterValue = null;
            return(false);
        }
    }
示例#10
0
        public override object Evaluate(Context context)
        {
            var name      = this.Fields.Get("NAME");
            var statement = this.Statements.FirstOrDefault(x => x.Name == "STACK");

            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            // if the statement is missing, create a stub one
            if (null == statement)
            {
                statement = new Statement
                {
                    Block = null,
                    Name  = "STACK"
                };
            }

            // tack the return value on as a block at the end of the statement
            if (this.Values.Any(x => x.Name == "RETURN"))
            {
                var valueBlock = new ValueBlock(this.Values.First(x => x.Name == "RETURN"));
                if (statement.Block == null)
                {
                    statement.Block = valueBlock;
                }
                else
                {
                    FindEndOfChain(statement.Block).Next = valueBlock;
                }
            }

            if (context.Functions.ContainsKey(name))
            {
                context.Functions[name] = statement;
            }
            else
            {
                context.Functions.Add(name, statement);
            }

            return(null);
        }
示例#11
0
    /// <summary>
    /// Clone Intance
    /// Deep Copy!!
    /// </summary>
    /// <returns></returns>
    public virtual Block Clone()
    {
        Block clonedBlock = (Block)this.MemberwiseClone(); // shallow copy

        //clonedBlock.BlockIndexInSouceCode = this.BlockIndexInSouceCode;

        Type[] parameterTypes = this.ParametersTypes;
        if (parameterTypes != null && parametersTypes.Length > 0)
        {
            for (int i = 1; i <= parametersTypes.Length; i++)
            {
                //Bad Performance!!!!!!!
                ValueBlock thisInput = (ValueBlock)(this.GetType().GetProperty("Input" + i.ToString()).GetValue(this)); // input of this instance
                this.GetType().GetProperty("Input" + i.ToString()).SetValue(clonedBlock, thisInput.Clone());            // set thisInput to input of clonedBlock
            }
        }


        return(clonedBlock);
    }
示例#12
0
        /// <summary>
        /// Initialize the blocks.
        /// </summary>
        /// <returns>List of block objects.</returns>
        public List <Entity> InitializeBlocks()
        {
            // Deserialize the blocks data.
            JToken[]      blocksData = JsonConvert.DeserializeObject <JToken[]>(_entityData.GetValue("blocks").ToString());
            List <Entity> blocks     = new List <Entity>();

            Texture2D texture = _game.Content.Load <Texture2D>("Images/Tile/Blocks");

            int tileSize = GetTileSize();

            int blockId;
            int positionX;
            int positionY;

            int    i;
            JToken blockData;

            // Convert the data to real objects.
            for (i = 0; i < blocksData.Length; i++)
            {
                blockData = blocksData[i];

                blockId   = (int)blockData["id"];
                positionX = (int)blockData["x"] * tileSize;
                positionY = (int)blockData["y"] * tileSize;

                Entity block = null;

                switch ((BlockType)blockId)
                {
                case BlockType.COINBLOCK:
                    block = new ValueBlock(new Vector2(positionX, positionY), 16, 16, (int)blockData["coins"], _game.Content, _level);
                    break;

                case BlockType.GIFTBLOCK:
                    PowerUp item = new Mushroom(Vector2.Zero, 16, 16, _game.Content, _level);
                    block = new GiftBlock(new Vector2(positionX, positionY), 16, 16, item, _game.Content, _level);
                    break;

                case BlockType.STONE:
                    block = new Tile(texture, new Rectangle(64, 16, 16, 16), new Vector2(positionX, positionY), 16, 16, true, _level);
                    break;

                case BlockType.CLOUD:
                    block = new Platform(texture, new Rectangle(32, 32, 16, 16), new Vector2(positionX, positionY), 16, 16, true, _level);
                    break;

                case BlockType.WOOD:
                    block = new Tile(texture, new Rectangle(64, 0, 16, 16), new Vector2(positionX, positionY), 16, 16, true, _level);
                    break;

                case BlockType.PIPE:

                    int column = 0;

                    if ((bool)blockData["top"])
                    {
                        column = 16;
                    }

                    block = new Pipe(texture, new Rectangle(column, 32, 16, 16), new Vector2(positionX, positionY), _level);

                    break;

                case BlockType.PLUNGER_PIPE:
                    block = new Pipe(texture, new Rectangle(16, 32, 16, 16), new Vector2(positionX, positionY), _level, _game.Content);
                    break;
                }

                if (block != null)
                {
                    blocks.Add(block);
                }
            }

            return(blocks);
        }