From 2ec11f60ad89c624c4e84bf4aaf743542c2da35a Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 23 Feb 2014 22:07:22 +0100 Subject: Clean and update comments --- src/esieequest/CommandWords.java | 25 +++++++++++-------------- src/esieequest/Parser.java | 35 +++++++++++++++-------------------- 2 files changed, 26 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/esieequest/CommandWords.java b/src/esieequest/CommandWords.java index 3d8855d..de1d132 100644 --- a/src/esieequest/CommandWords.java +++ b/src/esieequest/CommandWords.java @@ -1,25 +1,23 @@ package esieequest; /** - * This class is part of the "World of Zuul" application. "World of Zuul" is a - * very simple, text based adventure game. - * * This class holds an enumeration table of all command words known to the game. - * It is used to recognise commands as they are typed in. + * It is used to recognize commands as they are typed in. + * + * @author Pacien TRAN-GIRARD + * @author Benoit LUBRANO DI SBARAGLIONE * - * @author Michael Kolling and David J. Barnes + D.Bureau - * @version 2008.03.30 + 2013.09.15 + * @version February 2014 */ public class CommandWords { - // a constant array that holds all valid command words private static final String[] sValidCommands = { "go", "quit", "help", "look", "eat" }; /** - * Constructor - initialise the command words. + * Constructor - initialize the command words. */ public CommandWords() { - // nothing to do at the moment... - } // CommandWords() + + } /** * Check whether a given String is a valid command word. @@ -30,8 +28,7 @@ public class CommandWords { for (int i = 0; i < sValidCommands.length; i++) { if (sValidCommands[i].equals(pString)) return true; - } // for - // if we get here, the string was not found in the commands + } return false; - } // isCommand() -} // CommandWords + } +} diff --git a/src/esieequest/Parser.java b/src/esieequest/Parser.java index 4c09013..08f2bca 100644 --- a/src/esieequest/Parser.java +++ b/src/esieequest/Parser.java @@ -3,9 +3,6 @@ package esieequest; import java.util.Scanner; /** - * 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 @@ -15,12 +12,14 @@ import java.util.Scanner; * 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 + D.Bureau - * @version 2008.03.30 + 2013.09.15 + * @author Pacien TRAN-GIRARD + * @author Benoit LUBRANO DI SBARAGLIONE + * + * @version February 2014 */ public class Parser { - private CommandWords aValidCommands; // holds all valid command words - private Scanner aReader; // source of command input + private CommandWords aValidCommands; + private Scanner aReader; /** * Create a parser to read from the terminal window. @@ -28,36 +27,32 @@ public class Parser { public Parser() { this.aValidCommands = new CommandWords(); this.aReader = new Scanner(System.in); - } // Parser() + } /** * @return The next command from the user. */ public Command getCommand() { - String vInputLine; // will hold the full input line + String vInputLine; String vWord1 = null; String vWord2 = null; - System.out.print("> "); // print prompt + System.out.print("> "); vInputLine = this.aReader.nextLine(); - // Find up to two words on the line. Scanner vTokenizer = new Scanner(vInputLine); if (vTokenizer.hasNext()) { - vWord1 = vTokenizer.next(); // get first word + vWord1 = vTokenizer.next(); if (vTokenizer.hasNext()) { - vWord2 = vTokenizer.next(); // get second word - // note: we just ignore the rest of the input line. - } // if - } // if + vWord2 = vTokenizer.next(); + } + } - // Now check whether this word is known. If so, create a command - // with it. If not, create a "null" command (for unknown command). if (this.aValidCommands.isCommand(vWord1)) { return new Command(vWord1, vWord2); } else { return new Command(null, null); } - } // getCommand() -} // Parser + } +} -- cgit v1.2.3