//kiszámolja az animtime-t private static int GetTime(Robopreter.Command com) { int time = 800; if (com.comm == Commands.balra || com.comm == Commands.jobbra || com.comm == Commands.elore || com.comm == Commands.hatra) { time = (int)com.comm * 10; } return(time); }
public static void Run() { while (stmtQueue.Count > 0) { var currStmt = stmtQueue.Dequeue(); switch (currStmt.GetType().Name) { case "Sequence": var seq = (Sequence)currStmt; foreach (var item in seq.Statements) { stmtQueue.Enqueue(item); } break; case "Left": { var P = new Command(); P.comm = Commands.balra; ((Left)currStmt).Expression.Calc(); P.value = ((Left)currStmt).Expression.Return; Out.Add(P); } break; case "Right": { var P = new Command(); P.comm = Commands.jobbra; ((Right)currStmt).Expression.Calc(); P.value = ((Right)currStmt).Expression.Return; Out.Add(P); } break; case "Forward": { var P = new Command(); P.comm = Commands.elore; ((Forward)currStmt).Expression.Calc(); P.value = ((Forward)currStmt).Expression.Return; Out.Add(P); } break; case "Backward": { var P = new Command(); P.comm = Commands.hatra; ((Backward)currStmt).Expression.Calc(); P.value = ((Backward)currStmt).Expression.Return; Out.Add(P); } wait(); break; case "PenUp": { var P = new Command(); P.comm = Commands.tollatfel; Out.Add(P); } break; case "PenDown": { var P = new Command(); P.comm = Commands.tollatle; Out.Add(P); } break; case "Clear": { var P = new Command(); P.comm = Commands.torol; Out.Add(P); } break; case "Home": { var P = new Command(); P.comm = Commands.haza; Out.Add(P); } break; case "Circle": { var P = new Command(); P.comm = Commands.kor; ((Circle)currStmt).Expression.Calc(); P.value = ((Circle)currStmt).Expression.Return; Out.Add(P); } break; case "DeclareFunction": var stmtDeclareFunction = (DeclareFunction)currStmt; FuncDecl.Add(stmtDeclareFunction.Identity, stmtDeclareFunction); break; case "DeclareVariable": var stmtDeclareVariable = (DeclareVariable)currStmt; stmtDeclareVariable.Expression.Calc(); if (VarDecl.ContainsKey(stmtDeclareVariable.Identity)) { VarDecl[stmtDeclareVariable.Identity] = stmtDeclareVariable.Expression.Return; } else { VarDecl.Add(stmtDeclareVariable.Identity, stmtDeclareVariable.Expression.Return); } break; case "CallFunction": var stmtCallFunction = (CallFunction)currStmt; Call(stmtCallFunction.Identity, stmtCallFunction.Parameters); break; case "Print": break; case "IfElse": var stmtIfElse = (IfElse)currStmt; stmtIfElse.Condition.Calc(); try { if (Convert.ToBoolean(stmtIfElse.Condition.Return)) { stmtQueue.Enqueue(stmtIfElse.True); } else { stmtQueue.Enqueue(stmtIfElse.False); } } catch { throw new RPExeption(101, App.Current.TryFindResource("x_nologexp").ToString()); } break; case "Loop": var stmtLoop = (Loop)currStmt; var count = stmtLoop.Repeat.Calc(); if (count != null) { var savedQueue = stmtQueue.ToArray(); stmtQueue = new Queue<Stmt>(); for (int i = 0; i < count; i++) { stmtQueue.Enqueue(stmtLoop.Body); Run(); if (stopped) break; count = stmtLoop.Repeat.Calc() ?? 0; } stopped = false; foreach (var item in savedQueue) stmtQueue.Enqueue(item); } break; case "While": { var stmtWhile = (While)currStmt; stmtWhile.Condition.Calc(); var condition = (bool)stmtWhile.Condition.Return; var savedQueue = stmtQueue.ToArray(); stmtQueue = new Queue<Stmt>(); while (condition && !stopped) { stmtQueue.Enqueue(stmtWhile.Body); Run(); stmtWhile.Condition.Calc(); condition = (bool)stmtWhile.Condition.Return; } stopped = false; foreach (var item in savedQueue) stmtQueue.Enqueue(item); break; } case "Forever": { var stmtForever = (Forever)currStmt; var savedQueue = stmtQueue.ToArray(); stmtQueue = new Queue<Stmt>(); while (!stopped) { stmtQueue.Enqueue(stmtForever.Body); Run(); } stopped = false; foreach (var item in savedQueue) stmtQueue.Enqueue(item); break; } case "Output": var stmtOutput = (Output)currStmt; stmtOutput.Expression.Calc(); stmtStack.Peek().Add("$", stmtOutput.Expression.Return); break; case "Stop": stmtQueue.Clear(); stopped = true; break; case "Nop": break; } } }