private void Execute_Click(object sender, RoutedEventArgs e) { try { Directory.CreateDirectory(logDir); var logger = new CsvFileLogger(logDir + DateTime.Now.ToString().Replace(':', '-') + ".csv"); executor = new Executor(GetParsedCommands(), TimeSpan.FromMilliseconds(1), logger, this); SituationInfo.SetHandX(54); SituationInfo.SetHandY(1); executor.Start(); } catch { SituationInfo.SetHandX(54); SituationInfo.SetHandY(1); MessageBox.Show("Compilation error"); } }
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)); } }
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); }
public MainWindow() { try { InitializeComponent(); SituationInfo.mainWindow = this; string[] humanTxt = File.ReadLines(human).ToArray(); for (int i = 0; i < 44; i++) { string[] elements = humanTxt[i].Split(';'); for (int j = 0; j < 13; j++) { SituationInfo.humanMap[j, i] = int.Parse(elements[j] == "" ? "0" : elements[j]); if (SituationInfo.humanMap[j, i] != 0) { SolidColorBrush brush = Brushes.Yellow; switch (SituationInfo.humanMap[j, i]) { case -1: brush = Brushes.Blue; break; case -2: brush = Brushes.Red; break; case 2: brush = Brushes.Crimson; break; case 3: case 4: case 5: case 6: brush = Brushes.Brown; break; } Rectangle myRect = new Rectangle { Stroke = brush, Fill = brush, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Height = 20, Width = 20 }; Canvas.SetLeft(myRect, i * 20); Canvas.SetTop(myRect, j * 20); MainCanvas.Children.Add(myRect); } } } SituationInfo.SetHandX(54); SituationInfo.SetHandY(1); var program = File.ReadAllText(path); File.WriteAllText(log, ""); Program.Document.Blocks.Clear(); Program.Document.Blocks.Add(new Paragraph(new Run(program))); //program.Substring(1, program.Length - 2).GetBlocks(out _).Execute(); Executed.Document.Blocks.Clear(); } catch { MessageBox.Show("Config files are missing"); } }
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; } } }