Ejemplo n.º 1
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            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));
            }
            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            sp.X = (int)x;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));

            return(Completion.Void);
        }
Ejemplo n.º 2
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Degree == null)
            {
                return(Completion.Void);
            }
            double degree = 0;

            try
            {
                var c = Degree.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                degree = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", Degree));
            }

            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            if (sp.Direction != (int)degree)
            {
                sp.Direction = (int)degree;
                App.Current.Dispatcher.InvokeAsync(new Action(() =>
                {
                    (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
                }));
            }
            return(Completion.Void);
        }
Ejemplo n.º 3
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Size == null)
            {
                return(Completion.Void);
            }
            var c = Size.Execute(enviroment);

            if (c.Type != CompletionType.Value)
            {
                return(c);
            }
            int s = 0;

            try
            {
                s = TypeConverters.GetValue <int>(c.ReturnValue);
            }catch (Exception e)
            {
                return(Completion.Exception("Wrong number format", Size));
            }
            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            sp.Size = s;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }
Ejemplo n.º 4
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (ImageIndex == null)
            {
                return(Completion.Void);
            }
            var c = ImageIndex.Execute(enviroment);

            if (c.Type != CompletionType.Value)
            {
                return(c);
            }
            int    currentIndex = 0;
            Sprite sp           = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            if (TypeConverters.IsNumber(c.ReturnValue))
            {
                try
                {
                    currentIndex = TypeConverters.GetValue <int>(c.ReturnValue);
                }
                catch
                {
                    return(Completion.Exception("Wrong number format", ImageIndex));
                }
            }
            else
            {
                string name = c.ReturnValue + "";
                int    i    = 0;
                foreach (Resource r in sp.Images)
                {
                    if (r.DisplayName == name)
                    {
                        currentIndex = i;
                    }
                    i++;
                }
            }
            if (currentIndex < 0)
            {
                currentIndex = 0;
            }
            if (currentIndex >= sp.Images.Count)
            {
                currentIndex = 0;
            }
            sp.CurrentImage = currentIndex;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }
Ejemplo n.º 5
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            if (!sp.Visible)
            {
                sp.Visible = true;;
                App.Current.Dispatcher.InvokeAsync(new Action(() =>
                {
                    (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
                }));
            }
            return(Completion.Void);
        }
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            if (sp.RotationMode != RotationMode)
            {
                sp.RotationMode = RotationMode;
                App.Current.Dispatcher.InvokeAsync(new Action(() =>
                {
                    (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
                }));
            }

            return(Completion.Void);
        }
Ejemplo n.º 7
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            Sprite sp      = enviroment.GetValue("$$INSTANCE$$") as Sprite;
            int    current = sp.CurrentImage;

            current++;
            if (current == sp.Images.Count)
            {
                current = 0;
            }
            sp.CurrentImage = current;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }
Ejemplo n.º 8
0
        public Completion EndCall(ExecutionEnvironment _env)
        {
            ((_env.This as Instance).Class as Sprite).Size = size;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (_env.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            object result = size;

            return(new Completion(result));
        }
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            if (sp.RotationMode != RotationMode)
            {
                sp.RotationMode = RotationMode;
            }

            return(Completion.Void);
        }
Ejemplo n.º 10
0
 protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
 {
     try
     {
         var value = enviroment.GetValue(Variable);
         return(new Completion(value));
     }catch (Exception e)
     {
         return(Completion.Exception(string.Format(Properties.Language.VariableNotDefined, Variable), this));
     }
 }
Ejemplo n.º 11
0
        public Completion EndCall(ExecutionEnvironment _env)
        {
            Sprite sp = (_env.This as Instance).Class as Sprite;

            sp.X = (int)x;
            sp.Y = (int)y;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (_env.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// get function and variable value
 /// </summary>
 /// <param name="variable"></param>
 /// <returns></returns>
 public object GetValue(string variable)
 {
     if (currentVariables.ContainsKey(variable))
     {
         return(currentVariables[variable]);
     }
     if (_parent != null)
     {
         return(_parent.GetValue(variable));
     }
     return(null);
 }
Ejemplo n.º 13
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Degree == null)
            {
                return(Completion.Void);
            }
            double degree = 0;

            try
            {
                var c = Degree.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                degree = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", Degree));
            }
            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            if (Direction == RotationDirection.Clockwise)
            {
                sp.Direction += (int)degree;
            }
            else
            {
                sp.Direction -= (int)degree;
            }
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            double result = sp.Direction;

            return(new Completion(result));
        }
Ejemplo n.º 14
0
        public Completion EndCall(ExecutionEnvironment _env)
        {
            Sprite sp = (_env.This as Instance).Class as Sprite;

            if (sp.Visible)
            {
                ((_env.This as Instance).Class as Sprite).Visible = false;;
                App.Current.Dispatcher.InvokeAsync(new Action(() =>
                {
                    (_env.GetValue("$$Player") as ScriptPlayer).DrawScript();
                }));
            }
            return(Completion.Void);
        }
Ejemplo n.º 15
0
        public Completion EndCall(ExecutionEnvironment _env)
        {
            Sprite sp = (_env.This as Instance).Class as Sprite;

            if (sp.Direction != (int)degree)
            {
                ((_env.This as Instance).Class as Sprite).Direction = (int)degree;
                App.Current.Dispatcher.InvokeAsync(new Action(() =>
                {
                    (_env.GetValue("$$Player") as ScriptPlayer).DrawScript();
                }));
            }

            return(new Completion(degree));
        }
Ejemplo n.º 16
0
        public static SpeechSynthesizer GetSpeech(ExecutionEnvironment environment)
        {
            SpeechSynthesizer Speach = null;

            if (environment.HasValue(Name))
            {
                Speach = environment.GetValue(Name) as SpeechSynthesizer;
            }
            else
            {
                Speach = new SpeechSynthesizer();
                environment.GetBaseEnvironment().RegisterValue(Name, Speach);
            }
            return(Speach);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// get function and variable value
 /// </summary>
 /// <param name="variable"></param>
 /// <returns></returns>
 public object GetValue(string variable)
 {
     if (IsAborting)
     {
         throw new ExecutionAbortException(Properties.Language.ExecutionAborted);
     }
     if (currentVariables.ContainsKey(variable))
     {
         return(currentVariables[variable]);
     }
     if (_parent != null)
     {
         return(_parent.GetValue(variable));
     }
     throw new KeyNotFoundException();
 }
Ejemplo n.º 18
0
        public Completion EndCall(ExecutionEnvironment _env)
        {
            Sprite sp      = (_env.This as Instance).Class as Sprite;
            int    current = sp.CurrentImage;

            current++;
            if (current == sp.Images.Count)
            {
                current = 0;
            }
            sp.CurrentImage = current;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (_env.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }
Ejemplo n.º 19
0
        public Completion EndCall(ExecutionEnvironment _env)
        {
            bool reflection = false;

            if (_env.This.States.ContainsKey("$$ReflectionOnTouchSide&&") && (bool)_env.This.States["$$ReflectionOnTouchSide&&"])
            {
                reflection = true;
            }
            Sprite sp        = (_env.This as Instance).Class 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(() =>
            {
                (_env.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }
Ejemplo n.º 20
0
        public Completion EndCall(ExecutionEnvironment _env)
        {
            if (Direction == RotationDirection.Clockwise)
            {
                ((_env.This as Instance).Class as Sprite).Direction += (int)degree;
            }
            else
            {
                ((_env.This as Instance).Class as Sprite).Direction -= (int)degree;
            }
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (_env.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            double result = ((_env.This as Instance).Class as Sprite).Direction;

            return(new Completion(result));
        }
Ejemplo n.º 21
0
 public static ConsoleWindow GetConsole(ExecutionEnvironment enviroment)
 {
     if (!enviroment.HasValue("#$Console$#"))
     {
         Application.Current.Dispatcher.Invoke(() =>
         {
             consoleWindow       = new ConsoleWindow();
             consoleWindow.Owner = Application.Current.MainWindow;
             consoleWindow.Show();
         });
         enviroment.GetBaseEnvironment().RegisterValue("#$Console$#", consoleWindow);
     }
     else
     {
         consoleWindow = enviroment.GetValue("#$Console$#") as ConsoleWindow;
     }
     return(consoleWindow);
 }
Ejemplo n.º 22
0
 public Completion Assign(ExecutionEnvironment enviroment, object value)
 {
     if (value != null && !(value is BinaryTree))
     {
         return(Completion.Exception("value is not a binary tree type", this));
     }
     if (Node == null)
     {
         return(Completion.Exception("Null Exception", this));
     }
     if ((Node is Identifier))
     {
         string var = (Node as Identifier).Variable;
         if (!enviroment.HasValue(var))
         {
             return(Completion.Exception("varaible was not defined", Node));
         }
         BinaryTree tree = enviroment.GetValue(var) as BinaryTree;
         if (tree == null)
         {
             return(Completion.Exception("variable is not binary tree", Node));
         }
         tree.Left = value as BinaryTree;
         return(new Completion(value));
     }
     else
     {
         var c = Node.Execute(enviroment);
         if (!c.IsValue)
         {
             return(c);
         }
         if (c.ReturnValue is BinaryTree)
         {
             (c.ReturnValue as BinaryTree).Left = value as BinaryTree;
             return(new Completion(value));
         }
         else
         {
             return(Completion.Exception("value is not binary tree", Node));
         }
     }
 }
Ejemplo n.º 23
0
 public Completion Assign(ExecutionEnvironment enviroment, object value)
 {
     if (value != null && !(value is LinkedListEx))
     {
         return(Completion.Exception("value is not a linked list type", this));
     }
     if (Node == null)
     {
         return(Completion.Exception("Null Exception", this));
     }
     if ((Node is Identifier))
     {
         string var = (Node as Identifier).Variable;
         if (!enviroment.HasValue(var))
         {
             return(Completion.Exception("varaible was not defined", Node));
         }
         LinkedListEx tree = enviroment.GetValue(var) as LinkedListEx;
         if (tree == null)
         {
             return(Completion.Exception("variable is not linked list", Node));
         }
         tree.Previous = value as LinkedListEx;
         return(new Completion(value));
     }
     else
     {
         var c = Node.Execute(enviroment);
         if (!c.IsValue)
         {
             return(c);
         }
         if (c.ReturnValue is LinkedListEx)
         {
             (c.ReturnValue as LinkedListEx).Previous = value as LinkedListEx;
             return(new Completion(value));
         }
         else
         {
             return(Completion.Exception("value is not linked list", Node));
         }
     }
 }
Ejemplo n.º 24
0
        public static ConsoleWindow GetConsole(ExecutionEnvironment enviroment)
        {
            ConsoleWindow wnd = null;

            if (!enviroment.HasValue("#$Console$#"))
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    wnd       = new ConsoleWindow();
                    wnd.Owner = Application.Current.MainWindow;
                    wnd.Show();
                });
                enviroment.GetBaseEnvironment().RegisterValue("#$Console$#", wnd);
                ConsoleBaseStatement.consoleWindow = wnd;
            }
            else
            {
                wnd = enviroment.GetValue("#$Console$#") as ConsoleWindow;
            }
            return(wnd);
        }
Ejemplo n.º 25
0
 protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
 {
     if (Node == null)
     {
         return(Completion.Exception("Null Exception", this));
     }
     if ((Node is Identifier))
     {
         string var = (Node as Identifier).Variable;
         if (!enviroment.HasValue(var))
         {
             return(Completion.Exception("varaible was not defined", Node));
         }
         BinaryTree tree = enviroment.GetValue(var) as BinaryTree;
         if (tree == null)
         {
             return(Completion.Exception("variable is not binary tree", Node));
         }
         return(new Completion(tree.Left));
     }
     else
     {
         var c = Node.Execute(enviroment);
         if (!c.IsValue)
         {
             return(c);
         }
         if (c.ReturnValue is BinaryTree)
         {
             return(new Completion((c.ReturnValue as BinaryTree).Left));
         }
         else
         {
             return(Completion.Exception("value is not binary tree", Node));
         }
     }
 }
Ejemplo n.º 26
0
 protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
 {
     if (Node == null)
     {
         return(Completion.Exception("Null Exception", this));
     }
     if (Node is Identifier)
     {
         string var = (Node as Identifier).Variable;
         if (!enviroment.HasValue(var))
         {
             return(Completion.Exception("varaible was not defined", Node));
         }
         LinkedListEx tree = enviroment.GetValue(var) as LinkedListEx;
         if (tree == null)
         {
             return(Completion.Exception("variable is not linked list", Node));
         }
         return(new Completion(tree.Previous));
     }
     else
     {
         var c = Node.Execute(enviroment);
         if (!c.IsValue)
         {
             return(c);
         }
         if (c.ReturnValue is LinkedListEx)
         {
             return(new Completion((c.ReturnValue as LinkedListEx).Previous));
         }
         else
         {
             return(Completion.Exception("value is not linked list", Node));
         }
     }
 }
Ejemplo n.º 27
0
        public static DrawWindow GetCanvas(ExecutionEnvironment environment)
        {
            DrawWindow canvas = null;

            if (!environment.HasValue(CanvasName))
            {
                ExecutionEnvironment b = environment.GetBaseEnvironment();
                Application.Current.Dispatcher.Invoke(() =>
                {
                    canvas = new DrawWindow();
                    if (Application.Current.MainWindow != null)
                    {
                        canvas.Owner = Application.Current.MainWindow;
                    }
                    canvas.Show();
                });
                b.RegisterValue(CanvasName, canvas);
            }
            else
            {
                canvas = environment.GetValue(CanvasName) as DrawWindow;
            }
            return(canvas);
        }
Ejemplo n.º 28
0
        Nullable <DateTime> Callback(object value, object exception, ExecutionEnvironment _env)
        {
            Sprite sp = (_env.This as Instance).Class as Sprite;

            if (value is double)
            {
                currentIndex = int.Parse(value + "");
            }
            else
            {
                string name = value + "";
                int    i    = 0;
                foreach (Resource r in sp.Images)
                {
                    if (r.DisplayName == name)
                    {
                        currentIndex = i;
                    }
                    i++;
                }
            }
            if (currentIndex < 0)
            {
                currentIndex = 0;
            }
            if (currentIndex >= sp.Images.Count)
            {
                currentIndex = 0;
            }
            sp.CurrentImage = currentIndex;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (_env.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(null);
        }
Ejemplo n.º 29
0
        protected override Completion ExecuteImpl(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);
        }
Ejemplo n.º 30
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            return(new Completion(sp.Direction));
        }