import java.util.HashMap;

/**
 * This class is part of the "World of Zuul" application. 
 * "World of Zuul" is a very simple, text based adventure game.
 * 
 * This version holds mapping from command words to Responses
 */

public class CommandMapper
{
    private static HashMap<String, Response> responses; //responses to commands
    private static String allCmds;

    /**
     * Initialize the command response mapping
     * @param game The game being played.
     * @param helpIntroStr World data for help intro.
     */
    public static void init(Game game, String helpIntroStr) {
        responses = new HashMap<String, Response>();
        Response[] responseArray =    // insert yours in the sequence!
                     {new Goer(game),
                      new Helper(responses, helpIntroStr),
                      new Quitter()
                     };
        allCmds = "Your command words are:";
        for (Response r: responseArray) {
            String name = r.getCommandName();
            allCmds += " " + name; // in same order as responseArray
            responses.put(name, r);
        }
    }

    /**
     * Check whether a given String is a valid command word. 
     * @param aString The possible command word.
     * @return true if it is, false if it isn't.
     */
    public static boolean isCommand(String aString)
    {
        return responses.get(aString) != null;
    }

    /**
     * Return the command associated with a command word.
     * @param cmdWord The command word.
     * @return the Response for the command.
     */
    public static Response getResponse(String cmdWord)
    {
        return responses.get(cmdWord);
    }

    /**
     * @return a string containing all valid commands.
     */
    public static String allCommands()
    {
        return allCmds;
    }
}

