예제 #1
0
파일: Game.cs 프로젝트: antonydrew/comp170
        /**
         * Given a command: process (that is: Execute) the command.
         * Return true If the command ends the game, false otherwise.
         */
        private bool processCommand(Command command)
        {
            string cmd = command.GetCommandWord();

            if (!CommandMapper.isCommand(cmd))
            {
                Console.WriteLine("I don't know what you mean...");
                return(false);
            }
            bool toQuit;

            if (cmd == "help")
            {
                toQuit = helper.Execute(command);
            }
            else if (cmd == "go")
            {
                toQuit = goer.Execute(command);
            }
            else
            {
                toQuit = quitter.Execute(command);
            }
            return(toQuit);
        }
예제 #2
0
        /**
         * Print out some Help information.
         * Here we print some stupid, cryptic message and a list of the
         * command words.
         */
        public bool Execute(Command cmd)
        {
            if (!cmd.hasSecondWord())
            {
                Console.WriteLine(
                    @"You are lost. You are alone.
You wander around at the university.
                             
Your command words are:
   {0}

{1}", CommandMapper.GetAllCommands(), Help());
            }
            else if (details.ContainsKey(cmd.GetSecondWord()))
            {
                Console.WriteLine(details[cmd.GetSecondWord()]);
            }
            else
            {
                Console.WriteLine(
                    @"Unknown command {0}!  Command words are
    {1}", cmd.GetSecondWord(), CommandMapper.GetAllCommands());
            }
            return(false);
        }
예제 #3
0
 /**
  * Constructor for objects of class Helper
  */
 public Helper(Dictionary <string, Response> responses,
               CommandMapper commandMapper)
 {
     this.responses     = responses;
     this.commandMapper = commandMapper;
     CommandName        = "help";
 }
예제 #4
0
 /**
  * Create the game and initialise its internal map.
  */
 public Game()
 {
     places        = Place.createPlaces("placeData.txt");
     CurrentPlace  = places["outside"];
     commandMapper = new CommandMapper(this);
 }