001    /**
002     * This class is an abstract superclass for all command classes in the game.
003     * Each user command is implemented by a specific command subclass.
004     *
005     * Objects of class Command can store an optional argument word (a second
006     * word entered on the command line). If the command had only one word, 
007     * then the second word is <null>.
008     * 
009     * @author Michael Kolling and David J. Barnes
010     * @version 2011.07.31
011     */
012    
013    public abstract class Command
014    {
015        private String secondWord;
016    
017        /**
018         * Create a command object. First and second word must be supplied, but
019         * either one (or both) can be null. The command word should be null to
020         * indicate that this was a command that is not recognised by this game.
021         */
022        public Command()
023        {
024            secondWord = null;
025        }
026    
027        /**
028         * Return the second word of this command. If no
029         * second word was entered, the result is null.
030         */
031        public String getSecondWord()
032        {
033            return secondWord;
034        }
035    
036        /**
037         * Check whether a second word was entered for this 
038         * command.
039         */
040        public boolean hasSecondWord()
041        {
042            return secondWord != null;
043        }
044    
045        /**
046         * Define the second word of this command (the word
047         * entered after the command word). Null indicates that 
048         * there was no second word.
049         */
050        public void setSecondWord(String secondWord)
051        {
052            this.secondWord = secondWord;
053        }
054    
055        /**
056         * Execute this command. A flag is returned indicating whether
057         * the game is over as a result of this command.
058         * 
059         * @return True, if game should exit; false otherwise.
060         */
061        public abstract boolean execute(Player player);
062    }
063