aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-02-23 22:40:24 +0000
committerPacien TRAN-GIRARD2014-02-23 22:40:24 +0000
commiteef1285004b9bdf608002f9431905c0df329b870 (patch)
tree89d21ce6565ab8dd07346434fccdcd3d575bd3cd
parent3eb6c5630800038ae7d2f7eadfd4f705a6c22f6f (diff)
parent52595afbd4a0e2e2ed41f680c3b84742bf16b530 (diff)
downloadesieequest-eef1285004b9bdf608002f9431905c0df329b870.tar.gz
Merge branch 'zuul-better-v2' into 'master'
Zuul Better V2
-rw-r--r--report/progression.tex26
-rw-r--r--src/esieequest/CommandWords.java36
-rw-r--r--src/esieequest/Game.java244
-rw-r--r--src/esieequest/Parser.java42
-rw-r--r--src/esieequest/Room.java27
5 files changed, 210 insertions, 165 deletions
diff --git a/report/progression.tex b/report/progression.tex
index 2f25aea..da5e34e 100644
--- a/report/progression.tex
+++ b/report/progression.tex
@@ -73,16 +73,42 @@ The eat command has been added with the commit 40b9b4816.
73 73
74\subsection{showAll, showCommands} 74\subsection{showAll, showCommands}
75 75
76This modifications are part of the commit 79d33230b.
77
76\subsection{Adding commands} 78\subsection{Adding commands}
77 79
80Adding new commands would not require modifying the printHelp() method anymore.
81However, adding new commands and related functions would still require editing
82the Game class and its processCommand() method.
83
78\subsection{getCommandList} 84\subsection{getCommandList}
79 85
86The command list is not printed in the CommandWords class anymore. Instead, this
87class returns a String, forwarded by the Parser class, that is then printed in
88the Game class, thanks to commit 5f1d0ada2.
89
80\subsection{Comparison with reference} 90\subsection{Comparison with reference}
81 91
92The printLocationInfo() method, used only twice, has been trimmed by the commit
93590a932e5 and has been replaced by a call to the getLongDescription() method of
94the Room class.
95
96A missing getter for the Room description has been added as part of the commit
97f84606424.
98
99The loop building the command list String has been modified to use an Iterator
100with the commit 0c5793abf.
101
82\subsection{StringBuilder} 102\subsection{StringBuilder}
83 103
104The command list and the exit list are now created using a StringBuilder since
105commit ee5ec33aa. This avoids the creation of a new String object at each
106concatenation, and thus allows better performances.
107
84\subsection{Room objects} 108\subsection{Room objects}
85 109
110Rooms are now stored in an HashMap since commit f64f1ffb0, so they can be
111passed to any method in any class.
86 112
87\section{Zuul with images} 113\section{Zuul with images}
88 114
diff --git a/src/esieequest/CommandWords.java b/src/esieequest/CommandWords.java
index 3d8855d..e2d50f5 100644
--- a/src/esieequest/CommandWords.java
+++ b/src/esieequest/CommandWords.java
@@ -1,25 +1,23 @@
1package esieequest; 1package esieequest;
2 2
3/** 3/**
4 * This class is part of the "World of Zuul" application. "World of Zuul" is a
5 * very simple, text based adventure game.
6 *
7 * This class holds an enumeration table of all command words known to the game. 4 * This class holds an enumeration table of all command words known to the game.
8 * It is used to recognise commands as they are typed in. 5 * It is used to recognize commands as they are typed in.
6 *
7 * @author Pacien TRAN-GIRARD
8 * @author Benoit LUBRANO DI SBARAGLIONE
9 * 9 *
10 * @author Michael Kolling and David J. Barnes + D.Bureau 10 * @version February 2014
11 * @version 2008.03.30 + 2013.09.15
12 */ 11 */
13public class CommandWords { 12public class CommandWords {
14 // a constant array that holds all valid command words
15 private static final String[] sValidCommands = { "go", "quit", "help", "look", "eat" }; 13 private static final String[] sValidCommands = { "go", "quit", "help", "look", "eat" };
16 14
17 /** 15 /**
18 * Constructor - initialise the command words. 16 * Constructor - initialize the command words.
19 */ 17 */
20 public CommandWords() { 18 public CommandWords() {
21 // nothing to do at the moment... 19
22 } // CommandWords() 20 }
23 21
24 /** 22 /**
25 * Check whether a given String is a valid command word. 23 * Check whether a given String is a valid command word.
@@ -30,8 +28,18 @@ public class CommandWords {
30 for (int i = 0; i < sValidCommands.length; i++) { 28 for (int i = 0; i < sValidCommands.length; i++) {
31 if (sValidCommands[i].equals(pString)) 29 if (sValidCommands[i].equals(pString))
32 return true; 30 return true;
33 } // for 31 }
34 // if we get here, the string was not found in the commands
35 return false; 32 return false;
36 } // isCommand() 33 }
37} // CommandWords 34
35 /**
36 * Print all valid commands to System.out.
37 */
38 public String getCommandList() {
39 StringBuilder vStrBuilder = new StringBuilder();
40 for (String vCommand : sValidCommands) {
41 vStrBuilder.append(" ").append(vCommand);
42 }
43 return vStrBuilder.toString();
44 }
45}
diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java
index 350fa15..43db8f7 100644
--- a/src/esieequest/Game.java
+++ b/src/esieequest/Game.java
@@ -1,5 +1,7 @@
1package esieequest; 1package esieequest;
2 2
3import java.util.HashMap;
4
3/** 5/**
4 * The game engine. 6 * The game engine.
5 * 7 *
@@ -13,6 +15,7 @@ package esieequest;
13 * @version February 2014 15 * @version February 2014
14 */ 16 */
15public class Game { 17public class Game {
18 private HashMap<String, Room> aRooms;
16 private Room aCurrentRoom; 19 private Room aCurrentRoom;
17 private Parser aParser; 20 private Parser aParser;
18 21
@@ -20,9 +23,9 @@ public class Game {
20 * Create the game and initialize its internal map. 23 * Create the game and initialize its internal map.
21 */ 24 */
22 public Game() { 25 public Game() {
26 this.aRooms = new HashMap<String, Room>();
23 this.createRooms(); 27 this.createRooms();
24 this.printWelcome(); 28 this.aParser = new Parser();
25 this.printLocationInfo();
26 this.play(); 29 this.play();
27 } 30 }
28 31
@@ -30,7 +33,7 @@ public class Game {
30 * Main play routine. Loops until end of play. 33 * Main play routine. Loops until end of play.
31 */ 34 */
32 private void play() { 35 private void play() {
33 aParser = new Parser(); 36 this.printWelcome();
34 boolean vFinished = false; 37 boolean vFinished = false;
35 while (!vFinished) { 38 while (!vFinished) {
36 Command vCommand = this.aParser.getCommand(); 39 Command vCommand = this.aParser.getCommand();
@@ -45,134 +48,134 @@ public class Game {
45 */ 48 */
46 private void createRooms() { 49 private void createRooms() {
47 // create rooms 50 // create rooms
48 Room vAmphitheaterSeat = new Room("in the amphitheater"); 51 this.aRooms.put("AmphitheaterSeat", new Room("in the amphitheater"));
49 Room vAmphitheaterStage = new Room("on the amphitheater stage"); 52 this.aRooms.put("AmphitheaterStage", new Room("on the amphitheater stage"));
50 53
51 Room vCafeteriaStreet = new Room("in the main corridor, in front of the cafeteria"); 54 this.aRooms.put("CafeteriaStreet", new Room("in the main corridor, in front of the cafeteria"));
52 Room vCafeteria = new Room("at the cafeteria"); 55 this.aRooms.put("Cafeteria", new Room("at the cafeteria"));
53 56
54 Room vEsieespaceStreet = new Room("in the main corridor, in front of the ESIEEspace HQ"); 57 this.aRooms.put("EsieespaceStreet", new Room("in the main corridor, in front of the ESIEEspace HQ"));
55 Room vEsieespaceFront = new Room("in front of the ESIEEspace HQ"); 58 this.aRooms.put("EsieespaceFront", new Room("in front of the ESIEEspace HQ"));
56 Room vEsieespaceEntrance = new Room("at the ESIEEspace HQ entrance"); 59 this.aRooms.put("EsieespaceEntrance", new Room("at the ESIEEspace HQ entrance"));
57 Room vEsieespace = new Room("in the ESIEEspace HQ"); 60 this.aRooms.put("Esieespace", new Room("in the ESIEEspace HQ"));
58 61
59 Room vClubnixStreet = new Room("in the main corridor, in front of the Club*Nix"); 62 this.aRooms.put("ClubnixStreet", new Room("in the main corridor, in front of the Club*Nix"));
60 Room vClubnixFront = new Room("in front of the Club*Nix"); 63 this.aRooms.put("ClubnixFront", new Room("in front of the Club*Nix"));
61 Room vClubnixEntrance = new Room("at the Club*Nix entrance"); 64 this.aRooms.put("ClubnixEntrance", new Room("at the Club*Nix entrance"));
62 Room vClubnix = new Room("in the Club*Nix"); 65 this.aRooms.put("Clubnix", new Room("in the Club*Nix"));
63 66
64 Room vEntranceStreet = new Room("in the main corridor, at the reception"); 67 this.aRooms.put("EntranceStreet", new Room("in the main corridor, at the reception"));
65 Room vEntranceStairs = new Room("on the main entrance stairs"); 68 this.aRooms.put("EntranceStairs", new Room("on the main entrance stairs"));
66 Room vEntranceRoundabout = new Room("on the roundabout"); 69 this.aRooms.put("EntranceRoundabout", new Room("on the roundabout"));
67 70
68 Room vWingStreet = new Room("in font of wing #3"); 71 this.aRooms.put("WingStreet", new Room("in font of wing #3"));
69 Room vWingCorridorOne = new Room("in the corridor in wing #3, on the ground floor"); 72 this.aRooms.put("WingCorridorOne", new Room("in the corridor in wing #3, on the ground floor"));
70 Room vWingStairsOne = new Room("in the stairwell on the ground floor"); 73 this.aRooms.put("WingStairsOne", new Room("in the stairwell on the ground floor"));
71 Room vWingStairsTwo = new Room("in the stairwell on the first floor"); 74 this.aRooms.put("WingStairsTwo", new Room("in the stairwell on the first floor"));
72 Room vWingCorridorTwo = new Room("in the corridor in wind #3, on the first floor"); 75 this.aRooms.put("WingCorridorTwo", new Room("in the corridor in wind #3, on the first floor"));
73 Room vWingCorridorTwoOffice = new Room("in front of the office #3254"); 76 this.aRooms.put("WingCorridorTwoOffice", new Room("in front of the office #3254"));
74 Room vWingOffice = new Room("in the office #3254"); 77 this.aRooms.put("WingOffice", new Room("in the office #3254"));