Package com.bdtripp.hauntedhouse.model
Class Command
java.lang.Object
com.bdtripp.hauntedhouse.model.Command
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 Summary
ConstructorsConstructorDescriptionCommand(CommandWord firstWord, String secondWord, String thirdWord) Create a command with three words. -
Method Summary
Modifier and TypeMethodDescriptionReturns the primary command word supplied by the player.Returns the second word of the command, if present.Returns the third word of the command, if present.booleanIndicates whether the command includes a second word.booleanIndicates whether the command includes a third word.booleanIndicates whether the command word is unrecognized.
-
Constructor Details
-
Command
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
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
Returns the second word of the command, if present. This is typically the object or target of the command.- Returns:
- the second word, or
nullif the command contains only one word.
-
getThirdWord
Returns the third word of the command, if present. This is used for commands that require two arguments.- Returns:
- the third word, or
nullif 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 validCommandWord.- Returns:
trueif the command word is not understood.
-
hasSecondWord
public boolean hasSecondWord()Indicates whether the command includes a second word.- Returns:
trueif a second word is present.
-
hasThirdWord
public boolean hasThirdWord()Indicates whether the command includes a third word.- Returns:
trueif a third word is present.
-