diff options
-rw-r--r-- | src/esieequest/controller/Interpreter.java | 6 | ||||
-rw-r--r-- | src/esieequest/controller/Performer.java | 50 | ||||
-rw-r--r-- | src/esieequest/model/Game.java | 6 | ||||
-rw-r--r-- | src/esieequest/model/entities/Character.java | 25 | ||||
-rw-r--r-- | src/esieequest/model/entities/MovingCharacter.java | 33 | ||||
-rw-r--r-- | src/esieequest/model/entities/Sumobot.java | 32 | ||||
-rw-r--r-- | src/esieequest/model/map/Room.java | 27 | ||||
-rw-r--r-- | src/esieequest/model/map/TransporterDoor.java | 5 |
8 files changed, 182 insertions, 2 deletions
diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java index 5f9dafa..1895099 100644 --- a/src/esieequest/controller/Interpreter.java +++ b/src/esieequest/controller/Interpreter.java | |||
@@ -96,6 +96,12 @@ class Interpreter { | |||
96 | case USE: | 96 | case USE: |
97 | this.performer.useItem(command.getOption()); | 97 | this.performer.useItem(command.getOption()); |
98 | return; | 98 | return; |
99 | |||
100 | // characters related | ||
101 | case TALK: | ||
102 | this.performer.talk(command.getOption()); | ||
103 | return; | ||
104 | |||
99 | } | 105 | } |
100 | } | 106 | } |
101 | this.performer.echo("Unknown command."); | 107 | this.performer.echo("Unknown command."); |
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java index 17d2cd8..6526ef7 100644 --- a/src/esieequest/controller/Performer.java +++ b/src/esieequest/controller/Performer.java | |||
@@ -1,10 +1,15 @@ | |||
1 | package esieequest.controller; | 1 | package esieequest.controller; |
2 | 2 | ||
3 | import java.util.Collection; | ||
4 | import java.util.HashMap; | ||
3 | import java.util.HashSet; | 5 | import java.util.HashSet; |
6 | import java.util.Random; | ||
4 | import java.util.Set; | 7 | import java.util.Set; |
5 | 8 | ||
6 | import esieequest.model.Game; | 9 | import esieequest.model.Game; |
7 | import esieequest.model.commands.CommandWord; | 10 | import esieequest.model.commands.CommandWord; |
11 | import esieequest.model.entities.Character; | ||
12 | import esieequest.model.entities.MovingCharacter; | ||
8 | import esieequest.model.items.Beamer; | 13 | import esieequest.model.items.Beamer; |
9 | import esieequest.model.items.Inventory; | 14 | import esieequest.model.items.Inventory; |
10 | import esieequest.model.items.Item; | 15 | import esieequest.model.items.Item; |
@@ -156,6 +161,46 @@ class Performer { | |||
156 | this.echo("You died of exhaustion..."); | 161 | this.echo("You died of exhaustion..."); |
157 | this.quitGame(); | 162 | this.quitGame(); |
158 | } | 163 | } |
164 | |||
165 | this.moveMovingCharacters(); | ||
166 | } | ||
167 | |||
168 | /** | ||
169 | * Moves all MovingCharacters that can to adjacent rooms. | ||
170 | */ | ||
171 | private void moveMovingCharacters() { | ||
172 | final HashMap<Room, Room> movingCharactersPositions = new HashMap<Room, Room>(); | ||
173 | final Collection<Room> rooms = this.game.getRooms().values(); | ||
174 | for (final Room room : rooms) { | ||
175 | if (room.getCharacter() == null) { | ||
176 | continue; | ||
177 | } | ||
178 | if (room.getCharacter() instanceof MovingCharacter) { | ||
179 | if (!((MovingCharacter) room.getCharacter()).canMove()) { | ||
180 | continue; | ||
181 | } | ||
182 | final int randomIndex = new Random().nextInt(room.getExits().values().size()); | ||
183 | final Room destinationRoom = ((Door) room.getExits().values().toArray()[randomIndex]).getDestination(); | ||
184 | movingCharactersPositions.put(room, destinationRoom); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | for (final Room source : movingCharactersPositions.keySet()) { | ||
189 | this.swapCharacters(source, movingCharactersPositions.get(source)); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * Swaps the characters in the given rooms. | ||
195 | * | ||
196 | * @param source | ||
197 | * @param destination | ||
198 | */ | ||
199 | private void swapCharacters(final Room source, final Room destination) { | ||
200 | final Character characterS = source.getCharacter(); | ||
201 | final Character characterD = destination.getCharacter(); | ||
202 | destination.setCharacter(characterS); | ||
203 | source.setCharacter(characterD); | ||
159 | } | 204 | } |
160 | 205 | ||
161 | /** | 206 | /** |
@@ -267,4 +312,9 @@ class Performer { | |||
267 | } | 312 | } |
268 | } | 313 | } |
269 | } | 314 | } |
315 | |||
316 | public void talk(final String message) { | ||
317 | this.echo(this.game.getPlayer().getCurrentRoom().getCharacter().talk()); | ||
318 | } | ||
319 | |||
270 | } | 320 | } |
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java index 17fad02..87d3d51 100644 --- a/src/esieequest/model/Game.java +++ b/src/esieequest/model/Game.java | |||
@@ -4,6 +4,7 @@ import java.util.HashMap; | |||
4 | import java.util.HashSet; | 4 | import java.util.HashSet; |
5 | 5 | ||
6 | import esieequest.model.entities.Player; | 6 | import esieequest.model.entities.Player; |
7 | import esieequest.model.entities.Sumobot; | ||
7 | import esieequest.model.items.Beamer; | 8 | import esieequest.model.items.Beamer; |
8 | import esieequest.model.items.Item; | 9 | import esieequest.model.items.Item; |
9 | import esieequest.model.items.KeyCard; | 10 | import esieequest.model.items.KeyCard; |
@@ -37,6 +38,7 @@ public class Game { | |||
37 | this.createRooms(); | 38 | this.createRooms(); |
38 | this.linkRooms(); | 39 | this.linkRooms(); |
39 | this.createItems(); | 40 | this.createItems(); |
41 | this.createCharacters(); | ||
40 | this.goToRoom("AmphitheaterSeat"); | 42 | this.goToRoom("AmphitheaterSeat"); |
41 | } | 43 | } |
42 | 44 | ||
@@ -204,6 +206,10 @@ public class Game { | |||
204 | this.rooms.get("Dead-end").getItems().putItem("KeyCard", keyCard); | 206 | this.rooms.get("Dead-end").getItems().putItem("KeyCard", keyCard); |
205 | } | 207 | } |
206 | 208 | ||
209 | private void createCharacters() { | ||
210 | this.rooms.get("Locked room").setCharacter(new Sumobot()); | ||
211 | } | ||
212 | |||
207 | /** | 213 | /** |
208 | * Sets the current room designated by its name. | 214 | * Sets the current room designated by its name. |
209 | * | 215 | * |
diff --git a/src/esieequest/model/entities/Character.java b/src/esieequest/model/entities/Character.java new file mode 100644 index 0000000..03b1cfa --- /dev/null +++ b/src/esieequest/model/entities/Character.java | |||
@@ -0,0 +1,25 @@ | |||
1 | package esieequest.model.entities; | ||
2 | |||
3 | /** | ||
4 | * A character that can talk with the player. | ||
5 | * | ||
6 | * @author Pacien TRAN-GIRARD | ||
7 | */ | ||
8 | public abstract class Character { | ||
9 | |||
10 | private final String name; | ||
11 | |||
12 | public Character(final String name) { | ||
13 | this.name = name; | ||
14 | } | ||
15 | |||
16 | public abstract String talk(); | ||
17 | |||
18 | /** | ||
19 | * @return the name | ||
20 | */ | ||
21 | public String getName() { | ||
22 | return this.name; | ||
23 | } | ||
24 | |||
25 | } | ||
diff --git a/src/esieequest/model/entities/MovingCharacter.java b/src/esieequest/model/entities/MovingCharacter.java new file mode 100644 index 0000000..5265a28 --- /dev/null +++ b/src/esieequest/model/entities/MovingCharacter.java | |||
@@ -0,0 +1,33 @@ | |||
1 | package esieequest.model.entities; | ||
2 | |||
3 | /** | ||
4 | * A character that can move from rooms to rooms. | ||
5 | * | ||
6 | * @author Pacien TRAN-GIRARD | ||
7 | */ | ||
8 | public abstract class MovingCharacter extends Character { | ||
9 | |||
10 | private boolean canMove; | ||
11 | |||
12 | public MovingCharacter(final String name) { | ||
13 | super(name); | ||
14 | |||
15 | this.canMove = false; | ||
16 | } | ||
17 | |||
18 | /** | ||
19 | * @return the canMove | ||
20 | */ | ||
21 | public boolean canMove() { | ||
22 | return this.canMove; | ||
23 | } | ||
24 | |||
25 | /** | ||
26 | * @param canMove | ||
27 | * the canMove to set | ||
28 | */ | ||
29 | public void setCanMove(final boolean canMove) { | ||
30 | this.canMove = canMove; | ||
31 | } | ||
32 | |||
33 | } | ||
diff --git a/src/esieequest/model/entities/Sumobot.java b/src/esieequest/model/entities/Sumobot.java new file mode 100644 index 0000000..a700a71 --- /dev/null +++ b/src/esieequest/model/entities/Sumobot.java | |||
@@ -0,0 +1,32 @@ | |||
1 | package esieequest.model.entities; | ||
2 | |||
3 | import java.util.HashSet; | ||
4 | import java.util.Random; | ||
5 | |||
6 | public class Sumobot extends MovingCharacter { | ||
7 | |||
8 | private final Random randomGenerator; | ||
9 | private final HashSet<String> messages; | ||
10 | |||
11 | public Sumobot() { | ||
12 | super("Sumobot DK-02"); | ||
13 | |||
14 | this.randomGenerator = new Random(); | ||
15 | |||
16 | this.messages = new HashSet<String>(); | ||
17 | // exterminate ! | ||
18 | this.messages.add("絶やす !"); | ||
19 | // you will be deleted | ||
20 | this.messages.add("あなたが削除されます。"); | ||