protected override Completion ExecuteImpl(ExecutionEnvironment enviroment) { DateTime startTime; DateTime finishTime; double orgin_x; double orgin_y; double totalTime; if (X == null) { return(Completion.Void); } double x = 0; try { var c = X.Execute(enviroment); if (c.Type != CompletionType.Value) { return(c); } x = TypeConverters.GetValue <double>(c.ReturnValue); } catch { return(Completion.Exception("Wrong number format", X)); } if (Y == null) { return(Completion.Void); } double y = 0; try { var c = Y.Execute(enviroment); if (c.Type != CompletionType.Value) { return(c); } y = TypeConverters.GetValue <double>(c.ReturnValue); } catch { return(Completion.Exception("Wrong number format", Y)); } if (Time == null) { return(Completion.Void); } double time = 0; try { var c = Time.Execute(enviroment); if (c.Type != CompletionType.Value) { return(c); } time = TypeConverters.GetValue <double>(c.ReturnValue); } catch { return(Completion.Exception("Wrong number format", Time)); } Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite; if (x < 0) { x = 0; } if (x > CurrentEnviroment.ScreenWidth) { x = CurrentEnviroment.ScreenWidth; } if (y < 0) { y = 0; } if (y > CurrentEnviroment.ScreenHeight) { y = CurrentEnviroment.ScreenHeight; } orgin_x = sp.X; orgin_y = sp.Y; startTime = DateTime.Now; finishTime = DateTime.Now.AddSeconds(time); totalTime = (finishTime - startTime).TotalMilliseconds; while (true) { if (DateTime.Now > finishTime) { break; } double duration = (DateTime.Now - startTime).TotalMilliseconds; sp.X = (int)(orgin_x + (x - orgin_x) * duration / totalTime); sp.Y = (int)(orgin_y + (y - orgin_y) * duration / totalTime); App.Current.Dispatcher.InvokeAsync(new Action(() => { (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript(); })); Thread.Sleep(100); } sp.X = (int)x; sp.Y = (int)y; App.Current.Dispatcher.InvokeAsync(new Action(() => { (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript(); })); return(Completion.Void); }
public Completion Execute(ExecutionEnvironment enviroment) { if (Left == null || Right == null) { return(new Completion("Null Exception", CompletionType.Exception)); } var left = Left.Execute(enviroment); if (left.Type != CompletionType.Value) { return(left); } var right = Right.Execute(enviroment); if (right.Type != CompletionType.Value) { return(right); } Type T = TypeConverters.GetNumberTypes(left.ReturnValue, right.ReturnValue); if (T == null) { return(Completion.Exception("Only nuber can accepted", this)); } if (T.Equals(typeof(int))) { try { var l = TypeConverters.GetValue <int>(left.ReturnValue); var r = TypeConverters.GetValue <int>(right.ReturnValue); switch (Operator) { case Operator.Add: return(new Completion(l + r)); case Operator.Minus: return(new Completion(l - r)); case Operator.Mulitiply: return(new Completion(l * r)); case Operator.Divide: return(new Completion(l / r)); case Operator.Great: return(new Completion(l > r)); case Operator.GreatOrEqual: return(new Completion(l >= r)); case Operator.Less: return(new Completion(l < r)); case Operator.LessOrEqual: return(new Completion(l <= r)); case Operator.Equal: return(new Completion(l == r)); } return(Completion.Exception("Unknow Exception", this)); } catch (Exception e) { return(new Completion(e.Message, CompletionType.Exception)); } } if (T.Equals(typeof(float))) { try { var l = TypeConverters.GetValue <float>(left.ReturnValue); var r = TypeConverters.GetValue <float>(right.ReturnValue); switch (Operator) { case Operator.Add: return(new Completion(l + r)); case Operator.Minus: return(new Completion(l - r)); case Operator.Mulitiply: return(new Completion(l * r)); case Operator.Divide: return(new Completion(l / r)); case Operator.Great: return(new Completion(l > r)); case Operator.GreatOrEqual: return(new Completion(l >= r)); case Operator.Less: return(new Completion(l < r)); case Operator.LessOrEqual: return(new Completion(l <= r)); case Operator.Equal: return(new Completion(l == r)); } return(Completion.Exception("Unknow Exception", this)); } catch (Exception e) { return(new Completion(e.Message, CompletionType.Exception)); } } if (T.Equals(typeof(long))) { try { var l = TypeConverters.GetValue <long>(left.ReturnValue); var r = TypeConverters.GetValue <long>(right.ReturnValue); switch (Operator) { case Operator.Add: return(new Completion(l + r)); case Operator.Minus: return(new Completion(l - r)); case Operator.Mulitiply: return(new Completion(l * r)); case Operator.Divide: return(new Completion(l / r)); case Operator.Great: return(new Completion(l > r)); case Operator.GreatOrEqual: return(new Completion(l >= r)); case Operator.Less: return(new Completion(l < r)); case Operator.LessOrEqual: return(new Completion(l <= r)); case Operator.Equal: return(new Completion(l == r)); } return(Completion.Exception("Unknow Exception", this)); } catch (Exception e) { return(new Completion(e.Message, CompletionType.Exception)); } } { try { var l = TypeConverters.GetValue <double>(left.ReturnValue); var r = TypeConverters.GetValue <double>(right.ReturnValue); switch (Operator) { case Operator.Add: return(new Completion(l + r)); case Operator.Minus: return(new Completion(l - r)); case Operator.Mulitiply: return(new Completion(l * r)); case Operator.Divide: return(new Completion(l / r)); case Operator.Great: return(new Completion(l > r)); case Operator.GreatOrEqual: return(new Completion(l >= r)); case Operator.Less: return(new Completion(l < r)); case Operator.LessOrEqual: return(new Completion(l <= r)); case Operator.Equal: return(new Completion(l == r)); } return(Completion.Exception("Unknow Exception", this)); } catch (Exception e) { return(Completion.Exception(e.Message, this)); } } }
protected override Completion ExecuteImpl(ExecutionEnvironment enviroment) { if (Left == null) { return(Completion.Exception(Properties.Language.NullException, this)); } if (Right == null) { return(Completion.Exception(Properties.Language.NullException, this)); } var left = Left.Execute(enviroment); if (left.Type != CompletionType.Value) { return(left); } var right = Right.Execute(enviroment); if (right.Type != CompletionType.Value) { return(right); } if (IsLogicalOperator(Operator)) { return(ExecuteLogical(enviroment, left.ReturnValue, right.ReturnValue)); } if (Operator == Operator.Add) { if ((left.ReturnValue is string) || right.ReturnValue is string) { return(ExecuteStringAdd(enviroment, left.ReturnValue, right.ReturnValue)); } } if (Operator == Operator.Equal) { if (left.ReturnValue is string) { return(new Completion(left.ReturnValue is string && (left.ReturnValue as string).Equals(right.ReturnValue))); } if (right.ReturnValue is string) { return(new Completion(right.ReturnValue is string && (right.ReturnValue as string).Equals(left.ReturnValue))); } if (left.ReturnValue is bool) { return(new Completion(right.ReturnValue is bool && (bool)right.ReturnValue == (bool)left.ReturnValue)); } if (right.ReturnValue is bool) { return(new Completion(left.ReturnValue is bool && (bool)left.ReturnValue == (bool)right.ReturnValue)); } if (left.ReturnValue == null) { if (right.ReturnValue == null) { return(new Completion(true)); } else { return(new Completion(false)); } } if (right.ReturnValue == null) { if (left.ReturnValue == null) { return(new Completion(true)); } return(new Completion(false)); } } if (Operator == Operator.NotEqual) { if (left.ReturnValue is string) { return(new Completion(!(left.ReturnValue as string).Equals(right.ReturnValue))); } if (right.ReturnValue is string) { return(new Completion(!(right.ReturnValue as string).Equals(left.ReturnValue))); } if (left.ReturnValue is bool) { return(new Completion(!(right.ReturnValue is bool) || (bool)right.ReturnValue != (bool)left.ReturnValue)); } if (right.ReturnValue is bool) { return(new Completion(!(left.ReturnValue is bool) || (bool)left.ReturnValue != (bool)right.ReturnValue)); } if (left.ReturnValue == null) { if (right.ReturnValue != null) { return(new Completion(true)); } else { return(new Completion(false)); } } if (right.ReturnValue == null) { if (left.ReturnValue != null) { return(new Completion(true)); } return(new Completion(false)); } } if (Operator == Operator.Add) { if ((left.ReturnValue is DateTime) && right.ReturnValue is DateTime) { return(ExecuteStringAdd(enviroment, left.ReturnValue, right.ReturnValue)); } } Type T = TypeConverters.GetMaxTypes(left.ReturnValue, right.ReturnValue); if (T == null) { return(Completion.Exception(Properties.Language.NotNumber, this)); } if (Operator == Operator.Mod || Operator == Operator.BitAnd || Operator == Operator.BitOr || Operator == Operator.BitLeftShift || Operator == Operator.BitRightShift || Operator == Operator.BitExclusiveOr) { T = typeof(int); } if (T.Equals(typeof(char))) { try { var l = TypeConverters.GetValue <char>(left.ReturnValue); var r = TypeConverters.GetValue <char>(right.ReturnValue); switch (Operator) { case Operator.Add: return(new Completion(l + r)); case Operator.Minus: return(new Completion(l - r)); case Operator.Mulitiply: return(new Completion(l * r)); case Operator.Divide: return(new Completion(l / r)); case Operator.Mod: return(new Completion(l % r)); case Operator.Great: return(new Completion(l > r)); case Operator.GreatOrEqual: return(new Completion(l >= r)); case Operator.Less: return(new Completion(l < r)); case Operator.LessOrEqual: return(new Completion(l <= r)); case Operator.Equal: return(new Completion(l == r)); case Operator.NotEqual: return(new Completion(l != r)); case Operator.BitAnd: return(new Completion(l & r)); case Operator.BitOr: return(new Completion(l | r)); case Operator.BitLeftShift: return(new Completion(l << r)); case Operator.BitRightShift: return(new Completion(l >> r)); case Operator.BitExclusiveOr: return(new Completion(l ^ r)); } return(Completion.Exception(Properties.Language.UnknowException, this)); } catch (Exception e) { Console.WriteLine(e.StackTrace); return(Completion.Exception(e.Message, this)); } } if (T.Equals(typeof(int))) { try { var l = TypeConverters.GetValue <int>(left.ReturnValue); var r = TypeConverters.GetValue <int>(right.ReturnValue); switch (Operator) { case Operator.Add: return(new Completion(l + r)); case Operator.Minus: return(new Completion(l - r)); case Operator.Mulitiply: return(new Completion(l * r)); case Operator.Divide: return(new Completion(l / r)); case Operator.Mod: return(new Completion(l % r)); case Operator.Great: return(new Completion(l > r)); case Operator.GreatOrEqual: return(new Completion(l >= r)); case Operator.Less: return(new Completion(l < r)); case Operator.LessOrEqual: return(new Completion(l <= r)); case Operator.Equal: return(new Completion(l == r)); case Operator.NotEqual: return(new Completion(l != r)); case Operator.BitAnd: return(new Completion(l & r)); case Operator.BitOr: return(new Completion(l | r)); case Operator.BitLeftShift: return(new Completion(l << r)); case Operator.BitRightShift: return(new Completion(l >> r)); case Operator.BitExclusiveOr: return(new Completion(l ^ r)); } return(Completion.Exception(Properties.Language.UnknowException, this)); } catch (Exception e) { Console.WriteLine(e.StackTrace); return(Completion.Exception(e.Message, this)); } } if (T.Equals(typeof(float))) { try { var l = TypeConverters.GetValue <float>(left.ReturnValue); var r = TypeConverters.GetValue <float>(right.ReturnValue); switch (Operator) { case Operator.Add: return(new Completion(l + r)); case Operator.Minus: return(new Completion(l - r)); case Operator.Mulitiply: return(new Completion(l * r)); case Operator.Divide: return(new Completion(l / r)); case Operator.Great: return(new Completion(l > r)); case Operator.GreatOrEqual: return(new Completion(l >= r)); case Operator.Less: return(new Completion(l < r)); case Operator.LessOrEqual: return(new Completion(l <= r)); case Operator.Equal: return(new Completion(l == r)); case Operator.NotEqual: return(new Completion(l != r)); } return(Completion.Exception(Properties.Language.UnknowException, this)); } catch (Exception e) { return(Completion.Exception(e.Message, this)); } } if (T.Equals(typeof(long))) { try { var l = TypeConverters.GetValue <long>(left.ReturnValue); var r = TypeConverters.GetValue <long>(right.ReturnValue); switch (Operator) { case Operator.Add: return(new Completion(l + r)); case Operator.Minus: return(new Completion(l - r)); case Operator.Mulitiply: return(new Completion(l * r)); case Operator.Divide: return(new Completion(l / r)); case Operator.Great: return(new Completion(l > r)); case Operator.GreatOrEqual: return(new Completion(l >= r)); case Operator.Less: return(new Completion(l < r)); case Operator.LessOrEqual: return(new Completion(l <= r)); case Operator.Equal: return(new Completion(l == r)); case Operator.NotEqual: return(new Completion(l != r)); } return(Completion.Exception(Properties.Language.UnknowException, this)); } catch (Exception e) { return(Completion.Exception(e.Message, this)); } } { try { double l = TypeConverters.GetValue <double>(left.ReturnValue); double r = TypeConverters.GetValue <double>(right.ReturnValue); switch (Operator) { case Operator.Add: return(new Completion(l + r)); case Operator.Minus: return(new Completion(l - r)); case Operator.Mulitiply: return(new Completion(l * r)); case Operator.Divide: return(new Completion(l / r)); case Operator.Great: return(new Completion(l > r)); case Operator.GreatOrEqual: return(new Completion(l >= r)); case Operator.Less: return(new Completion(l < r)); case Operator.LessOrEqual: return(new Completion(l <= r)); case Operator.Equal: return(new Completion(l == r)); case Operator.NotEqual: return(new Completion(l != r)); } return(Completion.Exception(Properties.Language.UnknowException, this)); } catch (Exception e) { return(Completion.Exception(e.Message, this)); } } }
public Completion Execute(ExecutionEnvironment enviroment) { if (Step == null) { return(Completion.Void); } double degree = 0; try { var c = Step.Execute(enviroment); if (c.Type != CompletionType.Value) { return(c); } degree = TypeConverters.GetValue <double>(c.ReturnValue); } catch { return(Completion.Exception("Wrong number format", Step)); } bool reflection = false; if (enviroment.HasValue("$$ReflectionOnTouchSide&&") && enviroment.GetValue <bool>("$$ReflectionOnTouchSide&&")) { reflection = true; } Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite; int x = sp.X + (int)(Math.Cos(sp.Direction * Math.PI / 180) * degree); int y = sp.Y + (int)(Math.Sin(sp.Direction * Math.PI / 180) * degree); int direction = sp.Direction; if (reflection) { while (x < 0) { x = -x; direction = 180 - direction; } while (x > CurrentEnviroment.ScreenWidth) { x = CurrentEnviroment.ScreenWidth * 2 - x; direction = 180 - direction; } while (y < 0) { y = -y; direction = -direction; } while (y > CurrentEnviroment.ScreenHeight) { y = CurrentEnviroment.ScreenHeight * 2 - y; direction = -direction; } } sp.X = x; sp.Y = y; sp.Direction = direction; App.Current.Dispatcher.InvokeAsync(new Action(() => { (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript(); })); return(Completion.Void); }
protected override Completion ExecuteImpl(ExecutionEnvironment enviroment) { if (Right == null) { return(Completion.Exception(Properties.Language.NoValueAssigned, this)); } var right = Right.Execute(enviroment); if (right.Type != CompletionType.Value) { return(right); } if (Left == null) { return(right); } if (Left is IAssignment) { try { if (Operator == AssignmentOperator.Equal) { return((Left as IAssignment).Assign(enviroment, right.ReturnValue)); } var l = Left.Execute(enviroment); if (!l.IsValue) { return(l); } if (l.ReturnValue == null) { return(Completion.Exception(Properties.Language.VariableNullException, Left)); } Type lt = l.ReturnValue.GetType(); if (l.ReturnValue is string || right.ReturnValue is string) { if (Operator != AssignmentOperator.AddEqual) { return(Completion.Exception(Properties.Language.StringOnlySupport, this)); } return((Left as IAssignment).Assign(enviroment, l.ReturnValue + "" + right.ReturnValue)); } if (!TypeConverters.IsNumber(l.ReturnValue)) { return(Completion.Exception(Properties.Language.NotNumber, Left)); } if (!TypeConverters.IsNumber(right.ReturnValue)) { return(Completion.Exception(Properties.Language.NotNumber, Right)); } Type maxType = TypeConverters.GetMaxTypes(l.ReturnValue, right.ReturnValue); Console.Write(maxType); if (maxType.Equals(typeof(char))) { var lint = TypeConverters.GetValue <char>(l.ReturnValue); var rint = TypeConverters.GetValue <char>(right.ReturnValue); if (Operator == AssignmentOperator.AddEqual) { return((Left as IAssignment).Assign(enviroment, lint + rint)); } if (Operator == AssignmentOperator.MinusEqual) { return((Left as IAssignment).Assign(enviroment, lint - rint)); } if (Operator == AssignmentOperator.MulitiplyEqual) { return((Left as IAssignment).Assign(enviroment, lint * rint)); } if (Operator == AssignmentOperator.DivideEqual) { return((Left as IAssignment).Assign(enviroment, lint / rint)); } if (Operator == AssignmentOperator.ModEqual) { return((Left as IAssignment).Assign(enviroment, lint % rint)); } if (Operator == AssignmentOperator.BitAndEqual) { return((Left as IAssignment).Assign(enviroment, lint & rint)); } if (Operator == AssignmentOperator.BitExclusiveOrEqual) { return((Left as IAssignment).Assign(enviroment, lint ^ rint)); } if (Operator == AssignmentOperator.BitLeftShiftEqual) { return((Left as IAssignment).Assign(enviroment, lint << rint)); } if (Operator == AssignmentOperator.BitOrEqual) { return((Left as IAssignment).Assign(enviroment, lint | rint)); } if (Operator == AssignmentOperator.BitRightShiftEqual) { return((Left as IAssignment).Assign(enviroment, lint >> rint)); } return(Completion.Exception(Properties.Language.UnknowException, this)); } if (Operator == AssignmentOperator.BitAndEqual || Operator == AssignmentOperator.BitExclusiveOrEqual || Operator == AssignmentOperator.BitLeftShiftEqual || Operator == AssignmentOperator.BitOrEqual || Operator == AssignmentOperator.BitRightShiftEqual) { int lint = TypeConverters.GetValue <int>(l.ReturnValue); int rint = TypeConverters.GetValue <int>(right.ReturnValue); if (Operator == AssignmentOperator.BitAndEqual) { return((Left as IAssignment).Assign(enviroment, lint & rint)); } if (Operator == AssignmentOperator.BitExclusiveOrEqual) { return((Left as IAssignment).Assign(enviroment, lint ^ rint)); } if (Operator == AssignmentOperator.BitLeftShiftEqual) { return((Left as IAssignment).Assign(enviroment, lint << rint)); } if (Operator == AssignmentOperator.BitOrEqual) { return((Left as IAssignment).Assign(enviroment, lint | rint)); } if (Operator == AssignmentOperator.BitRightShiftEqual) { return((Left as IAssignment).Assign(enviroment, lint >> rint)); } return(Completion.Exception(Properties.Language.UnknowException, this)); } if (maxType.Equals(typeof(int))) { int lint = TypeConverters.GetValue <int>(l.ReturnValue); int rint = TypeConverters.GetValue <int>(right.ReturnValue); if (Operator == AssignmentOperator.AddEqual) { return((Left as IAssignment).Assign(enviroment, lint + rint)); } if (Operator == AssignmentOperator.MinusEqual) { return((Left as IAssignment).Assign(enviroment, lint - rint)); } if (Operator == AssignmentOperator.MulitiplyEqual) { return((Left as IAssignment).Assign(enviroment, lint * rint)); } if (Operator == AssignmentOperator.DivideEqual) { return((Left as IAssignment).Assign(enviroment, lint / rint)); } if (Operator == AssignmentOperator.ModEqual) { return((Left as IAssignment).Assign(enviroment, lint % rint)); } return(Completion.Exception(Properties.Language.UnknowException, this)); } else if (maxType.Equals(typeof(float))) { float lint = TypeConverters.GetValue <float>(l.ReturnValue); float rint = TypeConverters.GetValue <int>(right.ReturnValue); if (Operator == AssignmentOperator.AddEqual) { return((Left as IAssignment).Assign(enviroment, lint + rint)); } if (Operator == AssignmentOperator.MinusEqual) { return((Left as IAssignment).Assign(enviroment, lint - rint)); } if (Operator == AssignmentOperator.MulitiplyEqual) { return((Left as IAssignment).Assign(enviroment, lint * rint)); } if (Operator == AssignmentOperator.DivideEqual) { return((Left as IAssignment).Assign(enviroment, lint / rint)); } if (Operator == AssignmentOperator.ModEqual) { return((Left as IAssignment).Assign(enviroment, lint % rint)); } return(Completion.Exception(Properties.Language.UnknowException, this)); } else { double lint = TypeConverters.GetValue <double>(l.ReturnValue); double rint = TypeConverters.GetValue <double>(right.ReturnValue); if (Operator == AssignmentOperator.AddEqual) { return((Left as IAssignment).Assign(enviroment, lint + rint)); } if (Operator == AssignmentOperator.MinusEqual) { return((Left as IAssignment).Assign(enviroment, lint - rint)); } if (Operator == AssignmentOperator.MulitiplyEqual) { return((Left as IAssignment).Assign(enviroment, lint * rint)); } if (Operator == AssignmentOperator.DivideEqual) { return((Left as IAssignment).Assign(enviroment, lint / rint)); } if (Operator == AssignmentOperator.ModEqual) { return((Left as IAssignment).Assign(enviroment, lint % rint)); } return(Completion.Exception(Properties.Language.UnknowException, this)); } }catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); return(Completion.Exception(e.Message, this)); } } else { return(Completion.Exception(Properties.Language.InvalidBeforeEqual, Left)); } }