Ejemplo n.º 1
0
        private GameReply RunParser(string command)
        {
            var reply = new GameReply();

            // Run the natural language parser.
            var parsedCommand = Parser.ParseCommand(command);

            _commandQueue.AddCommand(parsedCommand);

            reply.State = GameStateEnum.Playing;
            reply.Reply = TextSubstitute.PerformSubstitution(CurrentRoom.ProcessCommand(parsedCommand));

            return(reply);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The ProcessCommand method is the primary way in which the player interacts with the game. When they type a command
        /// into the game, it is fed into this method which executes the parser to interpret what has been types which
        /// then results in a GameReply object that contains the broken down command ready for the game logic to use.
        /// </summary>
        /// <param name="command">The typed in command from the player.</param>
        /// <returns>The GameReply object that contains the interpreted command ready for the game to use.</returns>
        public GameReply ProcessCommand(string command)
        {
            var reply = new GameReply();

            if (!string.IsNullOrEmpty(command))
            {
                // Check for game specific override commands
                reply = CheckGameSpecificCommandOverrides(command);

                if (string.IsNullOrEmpty(reply.Reply))
                {
                    reply = RunParser(command);
                }

                return(reply);
            }

            reply.State = GameStateEnum.Playing;
            reply.Reply = string.Empty;

            return(reply);
        }
Ejemplo n.º 3
0
        private static GameReply CheckGameSpecificCommandOverrides(string command)
        {
            var reply = new GameReply();

            var lowerCase = command.ToLower();

            switch (lowerCase)
            {
            case "clear":
            case "cls":
            case "clearscreen":
            case "clear screen":

            {
                reply.State = GameStateEnum.Clearscreen;
                reply.Reply = lowerCase;
                return(reply);
            }

            case "quit":
            case "exit":
            case "run away":
            case "kill yourself":
            case "kill your self":
            {
                reply.State = GameStateEnum.Exit;
                reply.Reply = lowerCase;
                return(reply);
            }

            case "show score":
            case "score":
            case "view score":
            case "see score":
            case "what is my score":
            {
                reply.State = GameStateEnum.Score;
                reply.Reply = lowerCase;
                return(reply);
            }

            case "inventory":
            case "view inventory":
            {
                reply.State = GameStateEnum.Inventory;
                reply.Reply = lowerCase;
                return(reply);
            }

            case "help":
            case "help me":
            case "instructions":
            case "read manual":
            case "read the manual":
            case "manual":
            case "man":
            {
                reply.State = GameStateEnum.Help;
                reply.Reply = lowerCase;
                return(reply);
            }

            case "locations":
            case "visited":
            case "visited locations":
            {
                reply.State = GameStateEnum.Visited;
                reply.Reply = lowerCase;
                return(reply);
            }
            }

            reply.State = GameStateEnum.Playing;
            reply.Reply = "";

            return(reply);
        }