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 an enumeration of all command words known to the game. 006 * It is used to recognise commands as they are typed in. 007 * 008 * @author Michael Kolling and David J. Barnes 009 * @version 1.0 (February 2002) DBMOD: 04/04/2008 010 */ 011 012public class CommandWords 013{ 014 // a constant array that holds all valid command words 015 private static final String validCommands[] = { 016 "go", "quit", "help", "look", "eat", "back", "test", "take","drop","inventaire", "charge", "teleport" 017 }; 018 019 /** 020 * Constructor - initialise the command words. 021 */ 022 public CommandWords() 023 { 024 // nothing to do at the moment... 025 } 026 027 /** 028 * Check whether a given String is a valid command word. 029 * Return true if it is, false if it isn't. 030 **/ 031 public boolean isCommand(String aString) 032 { 033 for(int i = 0; i < validCommands.length; i++) { 034 if(validCommands[i].equals(aString)) 035 return true; 036 } 037 // if we get here, the string was not found in the commands 038 return false; 039 } 040 041 /** 042 * returns a String of all valid commands. 043 */ 044 public String getCommandList() 045 { 046 StringBuilder commands = new StringBuilder(); 047 for(int i = 0; i < validCommands.length; i++) { 048 commands.append( validCommands[i] + " " ); 049 } 050 return commands.toString(); 051 } 052}