Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

back command class2

By: ace on Jul 28th, 2010  |  syntax: None  |  size: 1.36 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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  Michael Kolling and David J. Barnes
  9.  * @version 1.0 (February 2002)
  10.  */
  11.  
  12. public class CommandWords
  13. {
  14.     // a constant array that holds all valid command words
  15.     private static final String[] validCommands = {
  16.         "go", "quit", "help", "look", "defuse","back"
  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.    
  41.     /*
  42. * Print all valid commands to System.out.
  43. */
  44. public String showAllCommands()
  45. {
  46. String allCommands = "";
  47. for(String s : validCommands)
  48.  {
  49.      allCommands = allCommands +" " + s;
  50. }
  51. return allCommands;
  52. }
  53.  
  54.  
  55. }