001public class CommandWords { 002 // Tableau constant qui contient toutes les commandes valides. 003 private static final String[] VALID_COMMANDS = { "go", "quit", "help", "look", "buy","back","test","take", "drop","items","eat","use","charge","open","close" }; 004 005 public CommandWords() { 006 007 } 008 /** 009 * Vérifie si un String correspond bien à une commande 010 * 011 * @return true si le String correspond à une commande valide. 012 */ 013 public boolean isCommand(final String pString) { 014 for (int i = 0; i < VALID_COMMANDS.length; i++) { 015 if (VALID_COMMANDS[i].equals(pString)) 016 return true; 017 } 018 return false; 019 } // isCommand() 020 /** 021 * Liste des commandes 022 * @return la liste des commandes sous la forme "go quit help" 023 */ 024 public String getCommandList() { 025 StringBuilder vOutput = new StringBuilder(); 026 for (String pCommand : VALID_COMMANDS) { 027 vOutput.append(pCommand+" "); 028 } 029 return vOutput.toString(); 030 } 031} // CommandWords