From dbcd6b62048f65886544ab8771c2cf276628db59 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 11 Feb 2014 21:40:11 +0100 Subject: Clean code (auto indent, update author and version) --- src/esieequest/Command.java | 57 +++--- src/esieequest/CommandWords.java | 57 +++--- src/esieequest/Game.java | 362 +++++++++++++++++++-------------------- src/esieequest/Main.java | 21 +-- src/esieequest/Parser.java | 108 ++++++------ src/esieequest/Room.java | 75 ++++---- 6 files changed, 315 insertions(+), 365 deletions(-) diff --git a/src/esieequest/Command.java b/src/esieequest/Command.java index 4ebc02a..f6afdea 100644 --- a/src/esieequest/Command.java +++ b/src/esieequest/Command.java @@ -4,39 +4,32 @@ package esieequest; * Représente une commande tapée au clavier qui provoque une action dans le jeu. * * @author Pacien TRAN-GIRARD - * @version Février 2013 + * @author Benoit LUBRANO DI SBARAGLIONE + * + * @version February 2014 */ -public class Command -{ - private String aCommandWord; - private String aSecondWord; +public class Command { + private String aCommandWord; + private String aSecondWord; + + public Command(final String pCommandWord, final String pSecondWord) { + this.aCommandWord = pCommandWord; + this.aSecondWord = pSecondWord; + } + + public String getCommandWord() { + return this.aCommandWord; + } + + public String getSecondWord() { + return this.aSecondWord; + } - /** - * Constructeur - */ - public Command(final String pCommandWord, final String pSecondWord) - { - this.aCommandWord = pCommandWord; - this.aSecondWord = pSecondWord; - } - - public String getCommandWord() - { - return this.aCommandWord; - } - - public String getSecondWord() - { - return this.aSecondWord; - } + public boolean isUnknown() { + return this.aCommandWord == null; + } - public boolean isUnknown() - { - return this.aCommandWord == null; - } - - public boolean hasSecondWord() - { - return this.aSecondWord != null; - } + public boolean hasSecondWord() { + return this.aSecondWord != null; + } } diff --git a/src/esieequest/CommandWords.java b/src/esieequest/CommandWords.java index d2dd2f3..3a77015 100644 --- a/src/esieequest/CommandWords.java +++ b/src/esieequest/CommandWords.java @@ -1,42 +1,37 @@ 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 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. - * - * @author Michael Kolling and David J. Barnes + D.Bureau + * + * @author Michael Kolling and David J. Barnes + D.Bureau * @version 2008.03.30 + 2013.09.15 */ -public class CommandWords -{ - // a constant array that holds all valid command words - private static final String[] sValidCommands = { - "go", "quit", "help" - }; +public class CommandWords { + // a constant array that holds all valid command words + private static final String[] sValidCommands = { "go", "quit", "help" }; - /** - * Constructor - initialise the command words. - */ - public CommandWords() - { - // nothing to do at the moment... - } // CommandWords() + /** + * Constructor - initialise the command words. + */ + public CommandWords() { + // nothing to do at the moment... + } // CommandWords() - /** - * Check whether a given String is a valid command word. - * @return true if a given string is a valid command, - * false if it isn't. - */ - public boolean isCommand( final String pString ) - { - for ( int i=0; i " ); // print prompt - - 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 - if ( vTokenizer.hasNext() ) { - vWord2 = vTokenizer.next(); // get second word - // note: we just ignore the rest of the input line. - } // if - } // if - - // 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() +public class Parser { + private CommandWords aValidCommands; // holds all valid command words + private Scanner aReader; // source of command input + + /** + * Create a parser to read from the terminal window. + */ + 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 vWord1 = null; + String vWord2 = null; + + System.out.print("> "); // print prompt + + 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 + if (vTokenizer.hasNext()) { + vWord2 = vTokenizer.next(); // get second word + // note: we just ignore the rest of the input line. + } // if + } // if + + // 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 diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java index 5fc9b82..a8db140 100644 --- a/src/esieequest/Room.java +++ b/src/esieequest/Room.java @@ -4,45 +4,42 @@ package esieequest; * Un lieu. * * @author Pacien TRAN-GIRARD - * @version Février 2013 + * @author Benoit LUBRANO DI SBARAGLIONE + * + * @version February 2014 */ -public class Room -{ - private String aDescription; - - public Room aNorthExit; - public Room aSouthExit; - public Room aEastExit; - public Room aWestExit; +public class Room { + private String aDescription; + + public Room aNorthExit; + public Room aSouthExit; + public Room aEastExit; + public Room aWestExit; + + public Room(final String pDescription) { + this.aDescription = pDescription; + } + + public String getDescription() { + return this.aDescription; + } - /** - * Constructeur - */ - public Room(final String pDescription) - { - this.aDescription = pDescription; - } - - /** - * @return description du lieu - */ - public String getDescription() - { - return this.aDescription; - } - - /** - * Défini les quatre sorties (lieux) du lieu - * @param pNorthExit lieu au Nord - * @param pSouthExit lieu au Sud - * @param pEastExit lieu à l'Est - * @param pWestExit lieu à l'Ouest - */ - public void setExits(final Room pNorthExit, final Room pSouthExit, final Room pEastExit, final Room pWestExit) - { - this.aNorthExit = pNorthExit; - this.aSouthExit = pSouthExit; - this.aEastExit = pEastExit; - this.aWestExit = pWestExit; - } + /** + * Défini les quatre sorties (lieux) du lieu + * + * @param pNorthExit + * lieu au Nord + * @param pSouthExit + * lieu au Sud + * @param pEastExit + * lieu à l'Est + * @param pWestExit + * lieu à l'Ouest + */ + public void setExits(final Room pNorthExit, final Room pSouthExit, final Room pEastExit, final Room pWestExit) { + this.aNorthExit = pNorthExit; + this.aSouthExit = pSouthExit; + this.aEastExit = pEastExit; + this.aWestExit = pWestExit; + } } -- cgit v1.2.3