Class Command

java.lang.Object
com.bdtripp.hauntedhouse.model.Command

public class Command extends Object
Represents a parsed player command. A Command consists of a primary verb and up to two optional arguments that specify the target or context of the action. For example, the input "give spade Beatrice" produces the command word "give" with "spade" and "Beatrice" as its arguments. Missing arguments are represented as null, allowing the game to distinguish between incomplete and fully specified commands.
Author:
Brian Tripp
  • Constructor Details

    • Command

      public Command(CommandWord firstWord, String secondWord, String thirdWord)
      Create a command with three words. Words may be null.
      Parameters:
      firstWord - the first word of the command.
      secondWord - the second word of the command.
      thirdWord - the third word of the command.
  • Method Details

    • getCommandWord

      public CommandWord getCommandWord()
      Returns the primary command word supplied by the player. This represents the action the player intends to perform.
      Returns:
      the first word of the command
    • getSecondWord

      public String getSecondWord()
      Returns the second word of the command, if present. This is typically the object or target of the command.
      Returns:
      the second word, or null if the command contains only one word.
    • getThirdWord

      public String getThirdWord()
      Returns the third word of the command, if present. This is used for commands that require two arguments.
      Returns:
      the third word, or null if the command does not include one.
    • isUnknown

      public boolean isUnknown()
      Indicates whether the command word is unrecognized. A command is considered unknown when its primary word does not match any valid CommandWord.
      Returns:
      true if the command word is not understood.
    • hasSecondWord

      public boolean hasSecondWord()
      Indicates whether the command includes a second word.
      Returns:
      true if a second word is present.
    • hasThirdWord

      public boolean hasThirdWord()
      Indicates whether the command includes a third word.
      Returns:
      true if a third word is present.