public void Interpret(string command, IProgram program) { var parts = ProcessCommand(command); if (parts.Length > 0) { if (string.Equals("step", parts[0], StringComparison.CurrentCultureIgnoreCase)) { CreateAndExecuteGameCommand((x, y) => new StepCommand(x, y), parts[1], parts[2], program); return; } else if (string.Equals("flag", parts[0], StringComparison.CurrentCultureIgnoreCase)) { CreateAndExecuteGameCommand((x, y) => new FlagCommand(x, y), parts[1], parts[2], program); return; } else if (string.Equals("exit", parts[0], StringComparison.CurrentCultureIgnoreCase)) { program.Exit(); return; } } //if not returned yet: program.AskForCommand(); }
public void InterpretNewGameYesNo(string command, IProgram program) { var processedCommand = ProcessCommand(command); if (processedCommand.Length < 1) { program.AskForNewGame(); } else if (string.Equals(processedCommand[0], "Yes", StringComparison.OrdinalIgnoreCase)) { program.NewGame(); } else { program.Exit(); } }
private static void HandleLine(string input, params string[] args) { if (currentProgram != null) //Check program { switch (input) { case "exit": //Exit program case "stop": case "quit": //Exit currentProgram.Exit(); currentProgram = null; //Clear Console.Clear(); Console.WriteLine("Welcome to Abide Command Line"); break; default: currentProgram.OnInput(input, args); break; //Program handle input } } else { switch (input) //Handle input { case "clear": Console.Clear(); Console.WriteLine("Welcome to Abide Command Line"); break; case "help": Console.WriteLine("Yeah uhh no thanks."); break; case "exit": case "stop": case "quit": Program.input = false; break; case "open": Console.WriteLine("Drag map file... (Or type path)"); string filename = Console.ReadLine(); OpenMap(filename); break; case "map": if (selectedMap == null) { Console.WriteLine("No selected map."); return; } Console.WriteLine($"Selected map is {selectedMap.Name} ({selectedMap.Build})"); Console.WriteLine("Would you like to go to the editor? (Y/n)"); if (Console.ReadKey().Key == ConsoleKey.Y) { currentProgram = new MapEditor(selectedMap); currentProgram.Start(); } break; default: Console.WriteLine($"Unknown input: \"{input}\""); break; } } }