加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Command.java 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
root 提交于 2021-06-23 22:38 . updated
/**
* This class is part of the "World of Zuul" application.
* "World of Zuul" is a very simple, text based adventure game.
*
* This class holds information about a command that was issued by the user.
* A command currently consists of two strings: a command word and a second
* word (for example, if the command was "take map", then the two strings
* obviously are "take" and "map").
*
* The way this is used is: Commands are already checked for being valid
* command words. If the user entered an invalid command (a word that is not
* known) then the command word is <null>.
*
* If the command had only one word, then the second word is <null>.
*
* @author Michael K?lling and David J. Barnes
* @version 2016.02.29
*/
public class Command
{
private Word commandWord;
private String secondWord;
/**
* Create a command object. First and second word must be supplied, but
* either one (or both) can be null.
* @param firstWord The first word of the command. Null if the command
* was not recognised.
* @param secondWord The second word of the command.
*/
public Command(String firstWord, String secondWord)
{
commandWord = Enum.valueOf(Word.class, firstWord.toUpperCase());
this.secondWord = secondWord;
}
/**
* Return the command word (the first word) of this command. If the
* command was not understood, the result is null.
* @return The command word.
*/
public Word getCommandWord()
{
return commandWord;
}
/**
* @return The second word of this command. Returns null if there was no
* second word.
*/
public String getSecondWord()
{
return secondWord;
}
/**
* @return true if this command was not understood.
*/
public boolean isUnknown()
{
return (commandWord == null);
}
/**
* @return true if the command has a second word.
*/
public boolean hasSecondWord()
{
return (secondWord != null);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化