Ejemplo n.º 1
0
        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));
                }
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
0
        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));
        }