Exemplo n.º 1
0
 public static int GetValue(string something)
 {
     something = something.Trim();
     if (something == "get_current_time")
     {
         return((int)sw.ElapsedMilliseconds);
     }
     if (something == "get_damage_level")
     {
         return((SituationInfo.GetHandX() < 45 && SituationInfo.GetHandY() < 15)?SituationInfo.humanMap[SituationInfo.GetHandY(), SituationInfo.GetHandX()] :-1);
     }
     if (something.StartsWith("$"))
     {
         return(Storage.UserVars[something.Substring(1)]);
     }
     else
     {
         return(int.Parse(something));
     }
 }
Exemplo n.º 2
0
        private void ProcessCommand(string command)
        {
            if (command.Trim() == "")
            {
                return;
            }

            var shift = 1;

            switch (command.Trim().Substring(0, command.Length - 1))
            {
            case "move_left":
                SituationInfo.SetHandX(SituationInfo.GetHandX() - shift);
                break;

            case "move_right":
                SituationInfo.SetHandX(SituationInfo.GetHandX() + shift);
                break;

            case "move_up":
                SituationInfo.SetHandY(SituationInfo.GetHandY() - shift);
                break;

            case "move_down":
                SituationInfo.SetHandY(SituationInfo.GetHandY() + shift);
                break;

            case "lower":
                main.ImgHand.Height -= shift * 20;
                main.ImgHand.Width  -= shift * 20;
                break;

            case "rise":
                main.ImgHand.Height += shift * 20;
                main.ImgHand.Width  += shift * 20;
                break;

            case "pick":
                if (SituationInfo.ScalpelX == SituationInfo.GetHandX() && SituationInfo.ScalpelY == SituationInfo.GetHandY())
                {
                    SituationInfo.InstrumentPicked = Instruments.Scalpel;
                }
                if (SituationInfo.NeedleX == SituationInfo.GetHandX() && SituationInfo.NeedleY == SituationInfo.GetHandY())
                {
                    SituationInfo.InstrumentPicked = Instruments.Needle;
                }
                if (SituationInfo.PatchX == SituationInfo.GetHandX() && SituationInfo.PatchY == SituationInfo.GetHandY())
                {
                    SituationInfo.InstrumentPicked = Instruments.Patch;
                }
                break;

            case "drop":
                SituationInfo.InstrumentPicked = Instruments.None;
                break;

            case "cut":
                if (SituationInfo.InstrumentPicked == Instruments.Scalpel || true)
                {
                    Line line1 = new Line
                    {
                        StrokeThickness = 6,
                        Stroke          = Brushes.Red,
                        X1 = SituationInfo.GetHandX() * 20,
                        X2 = SituationInfo.GetHandX() * 20 + 20,
                        Y1 = SituationInfo.GetHandY() * 20,
                        Y2 = SituationInfo.GetHandY() * 20 + 20
                    };
                    main.MainCanvas.Children.Add(line1);
                }
                break;

            case "sew":
                if (SituationInfo.InstrumentPicked == Instruments.Needle || true)
                {
                    Line line3 = new Line
                    {
                        StrokeThickness = 3,
                        Stroke          = Brushes.BlueViolet,
                        X1 = SituationInfo.GetHandX() * 20,
                        X2 = SituationInfo.GetHandX() * 20 + 20,
                        Y1 = SituationInfo.GetHandY() * 20,
                        Y2 = SituationInfo.GetHandY() * 20 + 20
                    };
                    Line line4 = new Line
                    {
                        StrokeThickness = 3,
                        Stroke          = Brushes.BlueViolet,
                        X1 = SituationInfo.GetHandX() * 20 + 20,
                        X2 = SituationInfo.GetHandX() * 20,
                        Y1 = SituationInfo.GetHandY() * 20,
                        Y2 = SituationInfo.GetHandY() * 20 + 20
                    };
                    main.MainCanvas.Children.Add(line3);
                    main.MainCanvas.Children.Add(line4);
                }
                break;

            case "patch":
                if (SituationInfo.InstrumentPicked == Instruments.Needle || true)
                {
                    Line line5 = new Line
                    {
                        StrokeThickness = 6,
                        Stroke          = Brushes.Orange,
                        X1 = SituationInfo.GetHandX() * 20,
                        X2 = SituationInfo.GetHandX() * 20 + 20,
                        Y1 = SituationInfo.GetHandY() * 20,
                        Y2 = SituationInfo.GetHandY() * 20 + 20
                    };
                    main.MainCanvas.Children.Add(line5);
                }
                break;

            case "call_human":
                MessageBox.Show("Human called");
                break;
            }

            LogText($"Executed {command}", LogLevel.Debug);
        }
Exemplo n.º 3
0
        public static void Execute(this List <BlockWithSubs> blocks)
        {
            for (int i = 0; i < blocks.Count; i++)
            {
                var trimmed = blocks[i].Simple.Trim();
                if (blocks[i].Blocks.Count == 0)
                {
                    if (trimmed.Contains(" is"))
                    {
                        var uvar = trimmed.MySubstring(1, trimmed.IndexOf(" is"));
                        Storage.UserVars[uvar] = Helper.Expression(trimmed.MySubstring(trimmed.IndexOf(" is") + 4, trimmed.Length - 1));
                        //WriteLog($"{uvar} IS {Storage.UserVars[uvar]} NOW");
                    }
                    else
                    {
                        switch (trimmed.Substring(0, trimmed.Length - 1))
                        {
                        case "move_left":
                            SituationInfo.SetHandX(SituationInfo.GetHandX() - 1);
                            break;

                        case "move_right":
                            SituationInfo.SetHandX(SituationInfo.GetHandX() + 1);
                            break;

                        case "move_up":
                            SituationInfo.SetHandY(SituationInfo.GetHandY() - 1);
                            break;

                        case "move_down":
                            SituationInfo.SetHandY(SituationInfo.GetHandY() + 1);
                            break;

                        case "cut":
                            SituationInfo.humanMap[SituationInfo.GetHandY(), SituationInfo.GetHandX()] -= 1;
                            break;
                        }
                        WriteLog(trimmed);
                    }
                    continue;
                }
                if (trimmed.StartsWith("for"))
                {
                    string range = trimmed.MySubstring(trimmed.IndexOf('(') + 1, trimmed.IndexOf(')'));
                    var    uvar  = range.MySubstring(0, range.IndexOf(" from"));
                    Storage.UserVars[uvar] = Helper.Expression(range.MySubstring(range.IndexOf(" from") + 6, range.IndexOf(" to")));
                    for (; Storage.UserVars[uvar] <= Helper.Expression(range.Substring(range.IndexOf(" to") + 4)); Storage.UserVars[uvar] = Storage.UserVars[uvar] + 1)
                    {
                        Execute(blocks[i].Blocks);
                    }
                    continue;
                }

                if (trimmed.StartsWith("while"))
                {
                    string cond = trimmed.MySubstring(trimmed.IndexOf('(') + 1, trimmed.IndexOf(')'));
                    while (Helper.Conditions(cond))
                    {
                        Execute(blocks[i].Blocks);
                    }
                    continue;
                }
                if (trimmed.StartsWith("if"))
                {
                    string cond = trimmed.MySubstring(trimmed.IndexOf('(') + 1, trimmed.IndexOf(')'));
                    if (Helper.Conditions(cond))
                    {
                        Execute(blocks[i].Blocks);
                    }
                    continue;
                }
            }
        }