From 613a5293396f190a8eef42fc3619219e6d1a2f25 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 11 Feb 2014 08:26:29 +0100 Subject: Import TP 2.1 badly written --- src/esieequest/Command.java | 42 +++++++++++ src/esieequest/CommandWords.java | 42 +++++++++++ src/esieequest/Game.java | 159 +++++++++++++++++++++++++++++++++++++++ src/esieequest/Main.java | 3 +- src/esieequest/Parser.java | 67 +++++++++++++++++ src/esieequest/Room.java | 48 ++++++++++++ 6 files changed, 360 insertions(+), 1 deletion(-) create mode 100644 src/esieequest/Command.java create mode 100644 src/esieequest/CommandWords.java create mode 100644 src/esieequest/Game.java create mode 100644 src/esieequest/Parser.java create mode 100644 src/esieequest/Room.java diff --git a/src/esieequest/Command.java b/src/esieequest/Command.java new file mode 100644 index 0000000..4ebc02a --- /dev/null +++ b/src/esieequest/Command.java @@ -0,0 +1,42 @@ +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 + */ +public class Command +{ + private String aCommandWord; + private String 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 hasSecondWord() + { + return this.aSecondWord != null; + } +} diff --git a/src/esieequest/CommandWords.java b/src/esieequest/CommandWords.java new file mode 100644 index 0000000..d2dd2f3 --- /dev/null +++ b/src/esieequest/CommandWords.java @@ -0,0 +1,42 @@ +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. + * + * @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" + }; + + /** + * 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() +} // Parser diff --git a/src/esieequest/Room.java b/src/esieequest/Room.java new file mode 100644 index 0000000..5fc9b82 --- /dev/null +++ b/src/esieequest/Room.java @@ -0,0 +1,48 @@ +package esieequest; + +/** + * Un lieu. + * + * @author Pacien TRAN-GIRARD + * @version Février 2013 + */ +public class Room +{ + private String aDescription; + + public Room aNorthExit; + public Room aSouthExit; + public Room aEastExit; + public Room aWestExit; + + /** + * 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; + } +} -- cgit v1.2.3