private StoryController(IStory story, Output output, CommandPrompt commandPrompt) { Context.Output = output ?? throw new ArgumentNullException("output"); Context.CommandPrompt = commandPrompt ?? throw new ArgumentNullException("commandPrompt"); Context.Story = story ?? throw new ArgumentNullException("story"); Context.Parser = new Parser(); }
public StoryController(IStory story) { Console.Title = story.Story; Output.Initialize(Console.Out, new WordWrap()); CommandPrompt.Initialize(Console.Out, Console.In); Context.Story = story ?? throw new ArgumentNullException("story"); }
public StoryController(IStory story, Output output, CommandPrompt commandPrompt) { if (story == null) throw new ArgumentNullException("story"); if (output == null) throw new ArgumentNullException("output"); if (commandPrompt == null) throw new ArgumentNullException("commandPrompt"); Context.Output = output; Context.CommandPrompt = commandPrompt; Context.Story = story; Context.Parser = new Parser(); }
public static bool YesOrNo(string question) { Print(question); while (true) { string[] affirmative = new[] { "y", "yes", "yep", "yeah" }; string[] negative = new[] { "n", "no", "nope", "nah", "naw" }; string response = CommandPrompt.GetInput(); if (!response.In(affirmative) && !response.In(negative)) { Print("Please answer yes or no."); } else { return(response.In(affirmative)); } } }
public void Run() { var story = Context.Story; story.Initialize(); MovePlayer.To(story.Location); while (!story.IsDone) { var room = CurrentRoom.Location; bool wasLit = CurrentRoom.IsLit(); var parser = new CommandLineParser(); var result = parser.Parse(CommandPrompt.GetInput()); if (result.Error.HasValue()) { Output.Print(result.Error); } else { var handler = result.CommandHandler(); handler.Run(); } if (!wasLit && CurrentRoom.IsLit() && CurrentRoom.Location == room) { CurrentRoom.Look(true); } if (wasLit && !CurrentRoom.IsLit()) { Output.Print("\r\nIt is now pitch dark in here!"); } story.Moves++; RunDaemons(); story.AfterTurn(); } }
public StoryController(IStory story, Output output, CommandPrompt commandPrompt) { if (story == null) { throw new ArgumentNullException("story"); } if (output == null) { throw new ArgumentNullException("output"); } if (commandPrompt == null) { throw new ArgumentNullException("commandPrompt"); } Context.Output = output; Context.CommandPrompt = commandPrompt; Context.Story = story; Context.Parser = new Parser(); }
private CommandLineParserResult GetInput(Verb verb) { var response = CommandPrompt.GetInput(); var tokens = SanitizeInput(response); if (tokens.Count == 0) { return(new CommandLineParserResult { Error = Messages.DoNotUnderstand }); } if (tokens[0].ToVerb() != null) { // a new command was entered instead of a partial response return(Parse(string.Join(' ', tokens))); } // parse original verb with the entered tokens return(Parse(verb, tokens)); }