1 Star 0 Fork 0

Louis彭/java期末作业

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CommandWords.java 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
Louis彭 提交于 2021-06-21 12:56 . update README.TXT.
/**
* This class is part of the "World of Zuul" application.
* "World of Zuul" is a very simple, text based adventure game.
*
* This class holds an enumeration of all command words known to the game.
* It is used to recognise commands as they are typed in.
*
* @author Michael Kölling and David J. Barnes
* @version 2016.02.29
*/
public class CommandWords
{
// a constant array that holds all valid command words
private static final String[] validCommands = {
"往", "退出", "帮助", "吃"
};
/**
* Constructor - initialise the command words.
*/
public static void printCommands(){
for(int i=0;i<validCommands.length;i++){
System.out.print(validCommands[i]+" ");
}
System.out.println();
}
/**
* Check whether a given String is a valid command word.
* @return true if a given string is a valid command,
* false if it isn't.
*/
public boolean isCommand(String aString)
{
for(int i = 0; i < validCommands.length; i++) {
if(validCommands[i].equals(aString))
return true;
}
// if we get here, the string was not found in the commands
return false;
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/louis-peng/java-final-assignment.git
git@gitee.com:louis-peng/java-final-assignment.git
louis-peng
java-final-assignment
java期末作业
master

搜索帮助