diff options
-rw-r--r-- | report/progression.tex | 39 | ||||
-rw-r--r-- | src/esieequest/Command.java | 6 | ||||
-rw-r--r-- | src/esieequest/Game.java | 263 | ||||
-rw-r--r-- | src/esieequest/GameEngine.java | 271 | ||||
-rw-r--r-- | src/esieequest/Parser.java | 21 | ||||
-rw-r--r-- | src/esieequest/Room.java | 16 | ||||
-rw-r--r-- | src/esieequest/UserInterface.java | 151 |
7 files changed, 492 insertions, 275 deletions
diff --git a/report/progression.tex b/report/progression.tex index da5e34e..f015634 100644 --- a/report/progression.tex +++ b/report/progression.tex | |||
@@ -114,11 +114,46 @@ passed to any method in any class. | |||
114 | 114 | ||
115 | \subsection{Game, GameEngine, UserInterface} | 115 | \subsection{Game, GameEngine, UserInterface} |
116 | 116 | ||
117 | The following methods was implemented as part of commit 54e102463. | ||
118 | |||
119 | \subsubsection{Game} | ||
120 | |||
121 | The constructor of this class instantiates the GameEngine and the UserInterface, | ||
122 | and set the output of the first to the second. | ||
123 | |||
124 | \subsubsection{GameEngine} | ||
125 | |||
126 | This class contains the attributes and methods previously contained in the Game | ||
127 | class. | ||
128 | |||
129 | Instead of printing to the standard console output, it prints to the GUI. | ||
130 | |||
131 | \subsubsection{UserInterface} | ||
132 | |||
133 | This class implements the graphical user interface of the game. It basically | ||
134 | creates the different window components and provides methods to | ||
135 | interact with them. | ||
136 | |||
117 | \subsection{Parser/Scanner} | 137 | \subsection{Parser/Scanner} |
118 | 138 | ||
119 | \subsection{UserInterface.addActionListener()} | 139 | Since commands are entered through a text field instead of the console, the |
140 | use of Scanner that read from the standard system input is not required anymore. | ||
141 | |||
142 | \subsection{addActionListener() and actionPerformed()} | ||
143 | |||
144 | The addActionListener() of an object x takes as parameter an object y that have | ||
145 | a actionPerformed() method. When an action event occurs on x, this method on y | ||
146 | is called and an ActionEvent is passed as parameter. | ||
147 | |||
148 | The actionPerformed() method then does the appropriate action according to the | ||
149 | event that happened. | ||
150 | |||
151 | \subsection{Add a button} | ||
120 | 152 | ||
121 | \subsection{UserInterface.actionPerformed()} | 153 | A help button was added with commit 7f153a4c1. The processCommand() method was |
154 | modified to take the command String as parameter instead of reading it only from | ||
155 | the text field, and the actionPerformed() method was modified accordingly to | ||
156 | forward the command. | ||
122 | 157 | ||
123 | 158 | ||
124 | \section{Zuul MVC} | 159 | \section{Zuul MVC} |
diff --git a/src/esieequest/Command.java b/src/esieequest/Command.java index fd05930..14c3d32 100644 --- a/src/esieequest/Command.java +++ b/src/esieequest/Command.java | |||
@@ -1,8 +1,6 @@ | |||
1 | package esieequest; | 1 | package esieequest; |
2 | 2 | ||
3 | /** | 3 | /** |
4 | * A text command that triggers an action in the game. | ||
5 | * | ||
6 | * This class holds information about a command that was issued by the user. A | 4 | * This class holds information about a command that was issued by the user. A |
7 | * command currently consists of two strings: a command word and a second word | 5 | * command currently consists of two strings: a command word and a second word |
8 | * (for example, if the command was "take map", then the two strings obviously | 6 | * (for example, if the command was "take map", then the two strings obviously |
@@ -33,8 +31,8 @@ public class Command { | |||
33 | * @param secondWord | 31 | * @param secondWord |
34 | * The second word of the command. | 32 | * The second word of the command. |
35 | */ | 33 | */ |
36 | public Command(final String pCommandWord, final String pSecondWord) { | 34 | public Command(final String pFirstWord, final String pSecondWord) { |
37 | this.aCommandWord = pCommandWord; | 35 | this.aCommandWord = pFirstWord; |
38 | this.aSecondWord = pSecondWord; | 36 | this.aSecondWord = pSecondWord; |
39 | } | 37 | } |
40 | 38 | ||
diff --git a/src/esieequest/Game.java b/src/esieequest/Game.java index 43db8f7..a35cfb4 100644 --- a/src/esieequest/Game.java +++ b/src/esieequest/Game.java | |||
@@ -1,6 +1,6 @@ | |||
1 | package esieequest; | 1 | package esieequest; |
2 | 2 | ||
3 | import java.util.HashMap; | 3 | import javax.swing.JApplet; |
4 | 4 | ||
5 | /** | 5 | /** |
6 | * The game engine. | 6 | * The game engine. |
@@ -14,263 +14,16 @@ import java.util.HashMap; | |||
14 | * | 14 | * |
15 | * @version February 2014 | 15 | * @version February 2014 |
16 | */ | 16 | */ |
17 | public class Game { | 17 | public class Game extends JApplet { |
18 | private HashMap<String, Room> aRooms; | 18 | private UserInterface aGui; |
19 | private Room aCurrentRoom; | 19 | private GameEngine aEngine; |
20 | private Parser aParser; | ||
21 | 20 | ||
22 | /** | 21 | /** |
23 | * Create the game and initialize its internal map. | 22 | * Create the game and initialise its internal map. |
24 | */ | 23 | */ |
25 | public Game() { | 24 | public Game() { |
26 | this.aRooms = new HashMap<String, Room>(); | 25 | this.aEngine = new GameEngine(); |
27 | this.createRooms(); | 26 | this.aGui = new UserInterface(this.aEngine); |
28 | this.aParser = new Parser(); | 27 | this.aEngine.setGUI(this.aGui); |
29 | this.play(); | ||
30 | } | ||
31 | |||
32 | /** | ||
33 | * Main play routine. Loops until end of play. | ||
34 | */ | ||
35 | private void play() { | ||
36 | this.printWelcome(); | ||
37 | boolean vFinished = false; | ||
38 | while (!vFinished) { | ||
39 | Command vCommand = this.aParser.getCommand(); | ||
40 | vFinished = this.processCommand(vCommand); | ||
41 | } | ||
42 | |||
43 | System.out.println("Thank you for playing. Good bye."); | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Create all the rooms and link their exits together. | ||
48 | */ | ||
49 | private void createRooms() { | ||
50 | // create rooms | ||
51 | this.aRooms.put("AmphitheaterSeat", new Room("in the amphitheater")); | ||
52 | this.aRooms.put("AmphitheaterStage", new Room("on the amphitheater stage")); | ||
53 | |||
54 | this.aRooms.put("CafeteriaStreet", new Room("in the main corridor, in front of the cafeteria")); | ||
55 | this.aRooms.put("Cafeteria", new Room("at the cafeteria")); | ||
56 | |||
57 | this.aRooms.put("EsieespaceStreet", new Room("in the main corridor, in front of the ESIEEspace HQ")); | ||
58 | this.aRooms.put("EsieespaceFront", new Room("in front of the ESIEEspace HQ")); | ||
59 | this.aRooms.put("EsieespaceEntrance", new Room("at the ESIEEspace HQ entrance")); | ||
60 | this.aRooms.put("Esieespace", new Room("in the ESIEEspace HQ")); | ||
61 | |||
62 | this.aRooms.put("ClubnixStreet", new Room("in the main corridor, in front of the Club*Nix")); | ||
63 | this.aRooms.put("ClubnixFront", new Room("in front of the Club*Nix")); | ||
64 | this.aRooms.put("ClubnixEntrance", new Room("at the Club*Nix entrance")); | ||
65 | this.aRooms.put("Clubnix", new Room("in the Club*Nix")); | ||
66 | |||
67 | this.aRooms.put("EntranceStreet", new Room("in the main corridor, at the reception")); | ||
68 | this.aRooms.put("EntranceStairs", new Room("on the main entrance stairs")); | ||
69 | this.aRooms.put("EntranceRoundabout", new Room("on the roundabout")); | ||
70 | |||
71 | this.aRooms.put("WingStreet", new Room("in font of wing #3")); | ||
72 | this.aRooms.put("WingCorridorOne", new Room("in the corridor in wing #3, on the ground floor")); | ||
73 | this.aRooms.put("WingStairsOne", new Room("in the stairwell on the ground floor")); | ||
74 | this.aRooms.put("WingStairsTwo", new Room("in the stairwell on the first floor")); | ||
75 | this.aRooms.put("WingCorridorTwo", new Room("in the corridor in wind #3, on the first floor")); | ||
76 | this.aRooms.put("WingCorridorTwoOffice", new Room("in front of the office #3254")); | ||
77 | this.aRooms.put("WingOffice", new Room("in the office #3254")); | ||
78 | |||
79 | this.aRooms.put("OffscriptEat", new Room("somewhere implementing hunger")); | ||
80 | this.aRooms.put("OffscriptEatPantry", new Room("in the pantry")); | ||
81 | this.aRooms.put("OffscriptTake", new Room("somewhere implementing weight")); | ||
82 | this.aRooms.put("OffscriptTakeStorageroom", new Room("in a storage room")); | ||
83 | this.aRooms.put("OffscriptTimeout", new Room("somewhere implementing time")); | ||
84 | this.aRooms.put("OffscriptTimeoutCountdownroom", new Room("in a dangerous room")); | ||
85 | this.aRooms.put("OffscriptTrapdoor", new Room("somewhere implementing a trap")); | ||
86 | this.aRooms.put("OffscriptTrapdoorDeadend", new Room("trapped")); | ||
87 | this.aRooms.put("OffscriptBeamer", new Room("somewhere implementing teleportation")); | ||
88 | this.aRooms.put("OffscriptBeamerAnchor", new Room("on a checkpoint")); | ||
89 | this.aRooms.put("OffscriptLock", new Room("somewhere implementing a doorlock")); | ||
90 | this.aRooms.put("OffscriptLockLockedroom", new Room("in a locked room that is not anymore")); | ||
91 | this.aRooms.put("OffscriptAlea", new Room("somewhere implementing alea")); | ||
92 | this.aRooms.put("OffscriptAleaRoomrandomizer", new Room("in a weird room that will transport you somewhere else")); | ||
93 | this.aRooms.put("OffscriptMovingcharacter", new Room("somewhere implementing a moving character")); | ||
94 | this.aRooms.put("OffscriptMovingcharacterMo", new Room("in M-O's room")); | ||
95 | |||
96 | // connect rooms | ||
97 | this.aRooms.get("AmphitheaterSeat").setExit("north", this.aRooms.get("AmphitheaterStage")); | ||
98 | this.aRooms.get("AmphitheaterStage").setExit("west", this.aRooms.get("Cafeteria")); | ||
99 | |||
100 | this.aRooms.get("CafeteriaStreet").setExit("south", this.aRooms.get("Cafeteria")); | ||
101 | this.aRooms.get("CafeteriaStreet").setExit("east", this.aRooms.get("EsieespaceStreet")); | ||
102 | this.aRooms.get("Cafeteria").setExit("north", this.aRooms.get("CafeteriaStreet")); | ||
103 | this.aRooms.get("Cafeteria").setExit("east", this.aRooms.get("AmphitheaterStage")); | ||
104 | |||
105 | this.aRooms.get("EsieespaceStreet").setExit("west", this.aRooms.get("Cafeteria")); | ||
106 | this.aRooms.get("EsieespaceStreet").setExit("south", this.aRooms.get("EsieespaceFront")); | ||
107 | this.aRooms.get("EsieespaceStreet").setExit("east", this.aRooms.get("EntranceStreet")); | ||
108 | this.aRooms.get("EsieespaceFront").setExit("north", this.aRooms.get("EsieespaceStreet")); | ||
109 | this.aRooms.get("EsieespaceFront").setExit("east", this.aRooms.get("EsieespaceEntrance")); | ||
110 | this.aRooms.get("EsieespaceEntrance").setExit("north", this.aRooms.get("Esieespace")); | ||
111 | this.aRooms.get("EsieespaceEntrance").setExit("west", this.aRooms.get("EsieespaceFront")); | ||
112 | this.aRooms.get("Esieespace").setExit("south", this.aRooms.get("EsieespaceEntrance")); | ||
113 | |||
114 | this.aRooms.get("ClubnixStreet").setExit("west", this.aRooms.get("WingStreet")); | ||
115 | this.aRooms.get("ClubnixStreet").setExit("south", this.aRooms.get("ClubnixFront")); | ||
116 | this.aRooms.get("ClubnixFront").setExit("north", this.aRooms.get("ClubnixStreet")); | ||
117 | this.aRooms.get("ClubnixFront").setExit("east", this.aRooms.get("ClubnixEntrance")); | ||
118 | this.aRooms.get("ClubnixEntrance").setExit("north", this.aRooms.get("Clubnix")); | ||
119 | this.aRooms.get("ClubnixEntrance").setExit("west", this.aRooms.get("ClubnixFront")); | ||
120 | this.aRooms.get("Clubnix").setExit("south", this.aRooms.get("ClubnixEntrance")); | ||
121 | |||
122 | this.aRooms.get("EntranceStreet").setExit("west", this.aRooms.get("EsieespaceStreet")); | ||
123 | this.aRooms.get("EntranceStreet").setExit("south", this.aRooms.get("EntranceStairs")); | ||
124 | this.aRooms.get("EntranceStreet").setExit("east", this.aRooms.get("WingStreet")); | ||
125 | this.aRooms.get("EntranceStairs").setExit("north", this.aRooms.get("EntranceStreet")); | ||
126 | this.aRooms.get("EntranceStairs").setExit("south", this.aRooms.get("EntranceRoundabout")); | ||
127 | this.aRooms.get("EntranceRoundabout").setExit("north", this.aRooms.get("EntranceStairs")); | ||
128 | |||
129 | this.aRooms.get("WingStreet").setExit("north", this.aRooms.get("WingCorridorOne")); | ||
130 | this.aRooms.get("WingStreet").setExit("west", th |