MasMasDo

Untitled

Nov 16th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. /**
  2.  * This class is the main class 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 Naufaliando
  9.  * @version 1.0
  10.  */
  11.  
  12. class CommandWords
  13. {
  14.     // a constant array that holds all valid command words
  15.     private static final String[] validCommands = {
  16.         "go", "quit", "help", "look"
  17.     };
  18.  
  19.     /**
  20.      * Constructor - initialise the command words.
  21.      */
  22.     public CommandWords()
  23.     {
  24.         // nothing to do at the moment...
  25.     }
  26.  
  27.     /**
  28.      * Check whether a given String is a valid command word.
  29.      * Return true if it is, false if it isn't.
  30.      */
  31.     public boolean isCommand(String aString)
  32.     {
  33.         for(int i = 0; i < validCommands.length; i++) {
  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