
/**
 * Response to try to go to a new room.
 */
public class Goer implements Response
{
    private Game game;

    /** 
     * Try to go to one direction. If there is an exit, enter the new
     * room, otherwise print an error message.
     * @return false(does not end game)
     */
    public boolean execute(String[] tokens)
    {
        if(tokens.length == 1) {
            // if there is no second word, we don't know where to go...
            System.out.println("Go where?");
            return false;
        }

        String direction = tokens[1];

        // Try to leave current room.
        Room nextRoom = game.getCurrentRoom().getExit(direction);

        if (nextRoom == null) {
            System.out.println("There is no door!");
        }
        else {
            game.setCurrentRoom(nextRoom);
            System.out.println(nextRoom.getLongDescription());
        }
        return false;
    }

    public String getCommandName()
    {
      return "go";
    }

    public String help()
    {
      return "Enter\n     go direction\n" +
         "to exit the current place in the specified direction.\n" +
         "The direction should be in the list of exits for the current place.";
    }

   public Goer(Game game)
    {
       this.game = game;
    }
}

