public static void If(GameContext context, bool condition, IOJMethod action) { if (condition) { action.Invoke(context); } }
public static void Repeat(GameContext context, int times, IOJMethod method) { for (int i = 0; i < times; i++) { method.Invoke(context); } }
public void MulTest2() { string code = "IncreaseHealth: 4*2"; IOJMethod method = parser.Parse(code, Filename); method.Invoke(context); Assert.AreEqual(18, context.hostCard.health); }
public void CmpTest2() { string code = "if:2 > 1, IncreaseHealth"; IOJMethod method = parser.Parse(code, Filename); method.Invoke(context); Assert.AreEqual(15, context.hostCard.health); }
public void AndTest1() { string code = "if:true && false, IncreaseHealth"; IOJMethod method = parser.Parse(code, Filename); method.Invoke(context); Assert.AreEqual(10, context.hostCard.health); }
public static void ForCards(GameContext context, List <Card> list, IOJMethod method) { foreach (var card in list) { context.cursor = card; method.Invoke(context); } }
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); }
public void NullTest() { string code = "setHealth:GetNullCard, 111"; IOJMethod method = parser.Parse(code, Filename); method.Invoke(context); Assert.AreEqual(10, context.hostCard.health); }
public void DefalutArgTest() { string code = "IncreaseHealth"; IOJMethod method = parser.Parse(code, Filename); method.Invoke(context); Assert.AreEqual(15, context.hostCard.health); }
public void ExceptionTest() { string code = "setHealth:,,,"; IOJMethod method = parser.Parse(code, Filename); method.Invoke(context); Assert.AreEqual(15, context.hostCard.health); }
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); }
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); }
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); } }
public static void Ifelse(GameContext context, bool condition, IOJMethod action, IOJMethod other) { if (condition) { action.Invoke(context); } else { other.Invoke(context); } }
/// <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())); }
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); }
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}"); }