001/** 002 * This class is the main class of the "World of Zuul" application. 003 * "World of Zuul" is a very simple, text based adventure game. 004 * 005 * This class holds information about a command that was issued by the user. 006 * A command currently consists of two strings: a command word and a second 007 * word (for example, if the command was "take map", then the two strings 008 * obviously are "take" and "map"). 009 * 010 * The way this is used is: Commands are already checked for being valid 011 * command words. If the user entered an invalid command (a word that is not 012 * known) then the command word is <null>. 013 * 014 * If the command had only one word, then the second word is <null>. 015 * 016 * @author Michael Kolling and David J. Barnes 017 * @version 1.0 (February 2002) 018 */ 019 020class Command 021{ 022 private String commandWord; 023 private String secondWord; 024 025 /** 026 * Create a command object. First and second word must be supplied, but 027 * either one (or both) can be null. The command word should be null to 028 * indicate that this was a command that is not recognised by this game. 029 */ 030 public Command(String firstWord, String secondWord) 031 { 032 commandWord = firstWord; 033 this.secondWord = secondWord; 034 } 035 036 /** 037 * Return the command word (the first word) of this command. If the 038 * command was not understood, the result is null. 039 */ 040 public String getCommandWord() 041 { 042 return commandWord; 043 } 044 045 /** 046 * Return the second word of this command. Returns null if there was no 047 * second word. 048 */ 049 public String getSecondWord() 050 { 051 return secondWord; 052 } 053 054 /** 055 * Return true if this command was not understood. 056 */ 057 public boolean isUnknown() 058 { 059 return (commandWord == null); 060 } 061 062 /** 063 * Return true if the command has a second word. 064 */ 065 public boolean hasSecondWord() 066 { 067 return (secondWord != null); 068 } 069} 070