Advertisement
lamaulfarid

CommandWords

Nov 19th, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. /**
  2. * This class is part of the "World of Zuul" application.
  3. * "World of Zuul" is a very simple, text based adventure game.
  4. *
  5. * This class holds an enumeration of all command words known to the game.
  6. * It is used to recognise commands as they are typed in.
  7. *
  8. * @author Ahmad Lamaul Farid
  9. * @version 12 November 2020
  10. */
  11.  
  12. public class CommandWords
  13. {
  14.     // a constant array that holds all valid command words
  15.     private static final String[] validCommands = {"go", "quit", "help"};
  16.      
  17.     /**
  18.     * Constructor - initialise the command words.
  19.     */
  20.     public CommandWords()
  21.     {
  22.     // nothing to do at the moment...
  23.     }
  24.      
  25.     /**
  26.     * Check whether a given String is a valid command word.
  27.     * @return true if a given string is a valid command,
  28.     * false if it isn't.
  29.     */
  30.     public boolean isCommand(String aString)
  31.     {
  32.         for(int i = 0; i < validCommands.length; i++)
  33.         {
  34.             if(validCommands[i].equals(aString))
  35.                 return true;
  36.         }
  37.         // if we get here, the string was not found in the commands
  38.         return false;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement