public Command getCommand(String inputLine) { String word1 = null; String word2 = null; String word3 = null; String[] words = inputLine.split(" "); if (words.length > 0) { // get first word word1 = words[0]; } if (words.length > 1) { // get second word word2 = words[1]; } if (words.length > 2) { word3 = words[2]; } // note: we just ignore the rest of the input line. Command command = commands.get(word1); if (command != null) { command.setSecondWord(word2); command.setThirdWord(word3); } return command; }
/** @return The next command from the user. */ public Command getCommands() { String inputLine; // will hold the full input line String word1 = null; String word2 = null; System.out.print("> "); // print prompt inputLine = reader.nextLine(); // Find up to two words on the line. Scanner tokenizer = new Scanner(inputLine); if (tokenizer.hasNext()) { word1 = tokenizer.next(); // get first word if (tokenizer.hasNext()) { word2 = tokenizer.next(); // get second word // note: we just ignore the rest of the input line. } } // Now check whether this word is known. If so, create a command // with it. If not, create a "null" command (for unknown command). if (commands.isCommand(word1)) { return new Command(word1, word2); } else { return new Command(null, word2); } }
public BattleCommand getUserBattleCommand(String s) { String word1 = null; StringTokenizer tokenizer = new StringTokenizer(s); if (tokenizer.hasMoreTokens()) word1 = tokenizer.nextToken(); return new BattleCommand(commands.getBattleCommandWord(word1)); }
private boolean processCommand(Command command) { switch (command.getCommandWord()) { case "quit": System.out.println("Thank you for playing!"); return false; case "help": System.out.println(words.getCommands()); return true; case "place": return place(command); } return true; }
public Command getUserCommand(String s) { String word1 = null; String word2 = null; // Find up to two words on the line. StringTokenizer tokenizer = new StringTokenizer(s); if (tokenizer.hasMoreTokens()) { word1 = tokenizer.nextToken(); // get first word if (tokenizer.hasMoreTokens()) { word2 = tokenizer.nextToken(); // get second word // note: we just ignore the rest of the input line. } } return new Command(commands.getCommandWord(word1), word2); }
public String showAllBattleCommands() { return commands.dspAllBattleCommands(); }
public void getCommands() { commands.showAll(); System.out.println(""); }
/** @param args */ public static void main(String[] args) { CommandWords.initialize(null); Game theGame = new Game(); theGame.play(); }
/** * Getter for CommandWords * * @return CommandWords.getCommandWords */ public String getCommandWords() { return CommandWords.getCommandWords(); }