Example #1
0
 public static void If(GameContext context, bool condition, IOJMethod action)
 {
     if (condition)
     {
         action.Invoke(context);
     }
 }
Example #2
0
 public static void Repeat(GameContext context, int times, IOJMethod method)
 {
     for (int i = 0; i < times; i++)
     {
         method.Invoke(context);
     }
 }
Example #3
0
        public void MulTest2()
        {
            string    code   = "IncreaseHealth: 4*2";
            IOJMethod method = parser.Parse(code, Filename);

            method.Invoke(context);
            Assert.AreEqual(18, context.hostCard.health);
        }
Example #4
0
        public void CmpTest2()
        {
            string    code   = "if:2 > 1, IncreaseHealth";
            IOJMethod method = parser.Parse(code, Filename);

            method.Invoke(context);
            Assert.AreEqual(15, context.hostCard.health);
        }
Example #5
0
        public void AndTest1()
        {
            string    code   = "if:true && false, IncreaseHealth";
            IOJMethod method = parser.Parse(code, Filename);

            method.Invoke(context);
            Assert.AreEqual(10, context.hostCard.health);
        }
Example #6
0
 public static void ForCards(GameContext context, List <Card> list, IOJMethod method)
 {
     foreach (var card in list)
     {
         context.cursor = card;
         method.Invoke(context);
     }
 }
Example #7
0
        public void NegTest1()
        {
            string    code   = "if:not false, IncreaseHealth: -1";
            IOJMethod method = parser.Parse(code, Filename);

            method.Invoke(context);
            Assert.AreEqual(9, context.hostCard.health);
        }
Example #8
0
        public void NullTest()
        {
            string    code   = "setHealth:GetNullCard, 111";
            IOJMethod method = parser.Parse(code, Filename);

            method.Invoke(context);
            Assert.AreEqual(10, context.hostCard.health);
        }
Example #9
0
        public void DefalutArgTest()
        {
            string    code   = "IncreaseHealth";
            IOJMethod method = parser.Parse(code, Filename);

            method.Invoke(context);
            Assert.AreEqual(15, context.hostCard.health);
        }
Example #10
0
        public void ExceptionTest()
        {
            string    code   = "setHealth:,,,";
            IOJMethod method = parser.Parse(code, Filename);

            method.Invoke(context);
            Assert.AreEqual(15, context.hostCard.health);
        }
Example #11
0
        public void RemapTest1()
        {
            string    code   = "iftrue: {IncreaseHealth:5}, IncreaseHealth:1";
            IOJMethod method = parser.Parse(code, Filename);

            method.Invoke(context);
            Assert.AreEqual(15, context.hostCard.health);
        }
Example #12
0
        public void ORTest3()
        {
            string    code   = "if:false or true, IncreaseHealth";
            IOJMethod method = parser.Parse(code, Filename);

            method.Invoke(context);
            Assert.AreEqual(15, context.hostCard.health);
        }
Example #13
0
        public void ForeachTest()
        {
            string    code   = "ForCards:AllEnemyCards, cur.setHealth:111";
            IOJMethod method = parser.Parse(code, Filename);

            method.Invoke(context);
            foreach (var card in context.enemies)
            {
                Assert.AreEqual(111, card.health);
            }
        }
Example #14
0
 public static void Ifelse(GameContext context, bool condition, IOJMethod action, IOJMethod other)
 {
     if (condition)
     {
         action.Invoke(context);
     }
     else
     {
         other.Invoke(context);
     }
 }
Example #15
0
        /// <summary>
        /// stmt当作oj函数调用
        ///     当stmt是映射时,需要提供args参数
        /// </summary>
        /// <param name="context"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public object Invoke(OJContext context, params object[] args)
        {
            if (isRemaped)
            {
                if (args.Length != this.args.Count)
                {
                    throw new RuntimeException($"{Name}参数个数不匹配:需要{this.args.Count}个 提供了{args.Length}个");
                }

                for (int i = 0; i < args.Length; i++)
                {
                    this.args[i].SetValue(args[i]);
                }
            }
            return(method.Invoke(context, this.args.ToArray()));
        }
Example #16
0
        public object Invoke(OJContext context, params object[] args)
        {
            //localVar.Clear();

            if (FinalType == FinalReturnType.OJMethod)
            {
                return(method.Invoke(context));
            }

            object returnValue = null;

            foreach (var stmt in stmts)
            {
                returnValue = stmt.Invoke(context, args);
            }
            return(returnValue);
        }
Example #17
0
        public static void TestMethod2()
        {
            //string code = @"if: true, {IncreaseHealth:;Log:'in ',health; iftrue}";
            string code = "if:true or false, log:'in'";
            Dictionary <string, string> remaps = new Dictionary <string, string>();

            remaps.Add("iftrue", "if:{Equals:health,10},$1");

            var         parser  = new OJParser(typeof(CardCommondDefiner), remaps);
            IOJMethod   method  = parser.Parse(code, Filename);
            GameContext context = new GameContext();

            context.hostCard = new Card()
            {
                health = 10
            };
            DateTime time = DateTime.Now;

            for (int i = 0; i < 1; i++)
            {
                method.Invoke(context);
            }
            Console.WriteLine($"{DateTime.Now - time}");
        }