private Command Prompt(Ask a) { var opts = a.Options(); // Print the possible options for (int i = 0; i < opts.Count; i++) { Out.WriteLine("(" + (i + 1) + ") " + opts[i].Text + " => [" + opts[i].ActionText() + "]"); } Command next = null; do // And prompt the user for a choice { try { next = a.Choose(ConsoleReader.ReadLine(a, a.WaitTime())); } catch (PromptTimeout) { Out.WriteLine("\nHey! Anyone home?"); } catch (InvalidChoice) { } Out.WriteLine("Choose an option from 1-" + opts.Count + "\n"); } while (next == null); // Print the selected option Out.WriteLine(" (selected Opt#" + (a.SelectedIdx + 1) + " => [" + a.Selected().ActionText() + "])\n"); return(next); }
private bool DoResponse(int timeout) { string response = null; try { response = ConsoleReader.ReadLine(timeout); int choice = (int)Convert.ChangeType(response, typeof(int)); this.gameEvent = new ChoiceEvent(choice); return(true); } catch (FormatException) { Display("Invalid response '" + response + "', reprompting\n"); } catch (TimeoutException) { Display("Timeout after " + timeout + "ms, reprompting\n"); } return(false); }