⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.java

📁 现在在国外大学里最流行的java学习软件,同时还有大量的example,在名为project的文件里.安装好后用bluej打开peoject的例子,可以进行你想要的任何变化.同时可以了解大量的源码
💻 JAVA
字号:
import java.util.Scanner;import java.util.StringTokenizer;/** * This class is part of the "World of Zuul" application.  * "World of Zuul" is a very simple, text based adventure game.   *  * This parser reads user input and tries to interpret it as an "Adventure" * command. Every time it is called it reads a line from the terminal and * tries to interpret the line as a two word command. It returns the command * as an object of class Command. * * The parser has a set of known command words. It checks user input against * the known commands, and if the input is not one of the known commands, it * returns a command object that is marked as an unknown command. *  * @author  Michael Kolling and David J. Barnes * @version 2006.03.30 */public class Parser {    private CommandWords commands;  // holds all valid command words    private Scanner reader;         // source of command input    /**     * Create a parser to read from the terminal window.     */    public Parser()     {        commands = new CommandWords();        reader = new Scanner(System.in);    }    /**     * @return The next command from the user.     */    public Command getCommand()     {        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);         }    }    /**     * Print out a list of valid command words.     */    public void showCommands()    {        commands.showAll();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -