diff options
-rw-r--r-- | res/res/snd/GAME_LOST.ogg | bin | 0 -> 1849460 bytes | |||
-rw-r--r-- | src/esieequest/controller/GameEngine.java | 34 | ||||
-rw-r--r-- | src/esieequest/model/characters/MovingCharacter.java | 14 | ||||
-rw-r--r-- | src/esieequest/model/characters/Sumobot.java | 33 | ||||
-rw-r--r-- | src/esieequest/model/events/Scene.java | 7 | ||||
-rw-r--r-- | src/esieequest/model/items/Beamer.java | 2 | ||||
-rw-r--r-- | src/esieequest/model/items/Item.java | 2 |
7 files changed, 69 insertions, 23 deletions
diff --git a/res/res/snd/GAME_LOST.ogg b/res/res/snd/GAME_LOST.ogg new file mode 100644 index 0000000..71dffae --- /dev/null +++ b/res/res/snd/GAME_LOST.ogg | |||
Binary files differ | |||
diff --git a/src/esieequest/controller/GameEngine.java b/src/esieequest/controller/GameEngine.java index 8e16ea1..8326607 100644 --- a/src/esieequest/controller/GameEngine.java +++ b/src/esieequest/controller/GameEngine.java | |||
@@ -4,6 +4,10 @@ import esieequest.controller.commands.Command; | |||
4 | import esieequest.model.Game; | 4 | import esieequest.model.Game; |
5 | import esieequest.model.Text; | 5 | import esieequest.model.Text; |
6 | import esieequest.model.characters.MovingCharacter; | 6 | import esieequest.model.characters.MovingCharacter; |
7 | import esieequest.model.events.Scene; | ||
8 | import esieequest.model.items.Beamer; | ||
9 | import esieequest.model.items.Item; | ||
10 | import esieequest.model.map.Room; | ||
7 | import esieequest.view.Viewable; | 11 | import esieequest.view.Viewable; |
8 | 12 | ||
9 | /** | 13 | /** |
@@ -73,15 +77,41 @@ public class GameEngine { | |||
73 | 77 | ||
74 | final String argument = input.getArgument(); | 78 | final String argument = input.getArgument(); |
75 | 79 | ||
76 | this.executeRoutines(); | 80 | this.executePreRoutines(); |
77 | command.execute(argument, this.game, this.view); | 81 | command.execute(argument, this.game, this.view); |
82 | this.executeAfterRoutines(); | ||
78 | } | 83 | } |
79 | 84 | ||
80 | /** | 85 | /** |
81 | * Performs routine actions executed every time a Command is entered. | 86 | * Performs routine actions executed every time a Command is entered. |
82 | */ | 87 | */ |
83 | private void executeRoutines() { | 88 | private void executePreRoutines() { |
84 | MovingCharacter.moveAll(); | 89 | MovingCharacter.moveAll(); |
85 | } | 90 | } |
86 | 91 | ||
92 | private void executeAfterRoutines() { | ||
93 | this.checkStalemate(); | ||
94 | } | ||
95 | |||
96 | private void checkStalemate() { | ||
97 | |||
98 | final boolean inDeadEnd = this.game.getPlayer().getCurrentRoom() == Room.DEAD_END; | ||
99 | final boolean canGoBack = this.game.getPlayer().canGoBack(); | ||
100 | final boolean hasBeamer = this.game.getPlayer().getInventory().hasItem(Item.BEAMER); | ||
101 | boolean canTeleport = hasBeamer; | ||
102 | |||
103 | if (hasBeamer) { | ||
104 | final Beamer beamer = (Beamer) Item.BEAMER.getItem(); | ||
105 | canTeleport = (beamer.getRoom() != null) && (beamer.getRoom() != Room.DEAD_END); | ||
106 | } | ||
107 | |||
108 | final boolean trapped = inDeadEnd && !canGoBack && !canTeleport; | ||
109 | |||
110 | if (trapped) { | ||
111 | this.view.playScene(Scene.GAME_LOST); | ||
112 | this.view.echo("You are trapped. You losed."); | ||
113 | } | ||
114 | |||
115 | } | ||
116 | |||
87 | } | 117 | } |
diff --git a/src/esieequest/model/characters/MovingCharacter.java b/src/esieequest/model/characters/MovingCharacter.java index b12c4ce..94aeaf1 100644 --- a/src/esieequest/model/characters/MovingCharacter.java +++ b/src/esieequest/model/characters/MovingCharacter.java | |||
@@ -4,6 +4,7 @@ import java.util.ArrayList; | |||
4 | import java.util.List; | 4 | import java.util.List; |
5 | import java.util.Random; | 5 | import java.util.Random; |
6 | 6 | ||
7 | import lombok.Getter; | ||
7 | import lombok.Setter; | 8 | import lombok.Setter; |
8 | import net.pacien.util.CleanJSONObject; | 9 | import net.pacien.util.CleanJSONObject; |
9 | 10 | ||
@@ -40,9 +41,10 @@ public abstract class MovingCharacter extends SimpleCharacter { | |||
40 | private static final String CURRENT_DIRECTION_LABEL = "D"; | 41 | private static final String CURRENT_DIRECTION_LABEL = "D"; |
41 | private Direction currentDirection; | 42 | private Direction currentDirection; |
42 | 43 | ||
43 | private static final String CAN_MOVE_LABEL = "M"; | 44 | private static final String MOBILE_LABEL = "M"; |
45 | @Getter | ||
44 | @Setter | 46 | @Setter |
45 | private boolean canMove; | 47 | private boolean mobile; |
46 | 48 | ||
47 | /** | 49 | /** |
48 | * Creates a MovingCharacter with a given name and location. | 50 | * Creates a MovingCharacter with a given name and location. |
@@ -60,7 +62,7 @@ public abstract class MovingCharacter extends SimpleCharacter { | |||
60 | 62 | ||
61 | this.currentRoom = room; | 63 | this.currentRoom = room; |
62 | this.currentDirection = direction; | 64 | this.currentDirection = direction; |
63 | this.canMove = false; | 65 | this.mobile = false; |
64 | } | 66 | } |
65 | 67 | ||
66 | /** | 68 | /** |
@@ -69,7 +71,7 @@ public abstract class MovingCharacter extends SimpleCharacter { | |||
69 | * Character. | 71 | * Character. |
70 | */ | 72 | */ |
71 | public void move() { | 73 | public void move() { |
72 | if (!this.canMove) { | 74 | if (!this.mobile) { |
73 | return; | 75 | return; |
74 | } | 76 | } |
75 | 77 | ||
@@ -106,7 +108,7 @@ public abstract class MovingCharacter extends SimpleCharacter { | |||
106 | if (this.currentDirection != null) { | 108 | if (this.currentDirection != null) { |
107 | o.put(MovingCharacter.CURRENT_DIRECTION_LABEL, this.currentDirection.name()); | 109 | o.put(MovingCharacter.CURRENT_DIRECTION_LABEL, this.currentDirection.name()); |
108 | } | 110 | } |
109 | o.put(MovingCharacter.CAN_MOVE_LABEL, this.canMove); | 111 | o.put(MovingCharacter.MOBILE_LABEL, this.mobile); |
110 | 112 | ||
111 | return o; | 113 | return o; |
112 | } | 114 | } |
@@ -116,7 +118,7 @@ public abstract class MovingCharacter extends SimpleCharacter { | |||
116 | this.currentRoom = Room.valueOf((String) o.get(MovingCharacter.CURRENT_ROOM_LABEL)); | 118 | this.currentRoom = Room.valueOf((String) o.get(MovingCharacter.CURRENT_ROOM_LABEL)); |
117 | this.currentDirection = Direction.valueOf((String) o | 119 | this.currentDirection = Direction.valueOf((String) o |
118 | .get(MovingCharacter.CURRENT_DIRECTION_LABEL)); | 120 | .get(MovingCharacter.CURRENT_DIRECTION_LABEL)); |
119 | this.canMove = (Boolean) o.get(MovingCharacter.CAN_MOVE_LABEL); | 121 | this.mobile = (Boolean) o.get(MovingCharacter.MOBILE_LABEL); |
120 | } | 122 | } |
121 | 123 | ||
122 | } | 124 | } |
diff --git a/src/esieequest/model/characters/Sumobot.java b/src/esieequest/model/characters/Sumobot.java index fb4e7b3..baeabad 100644 --- a/src/esieequest/model/characters/Sumobot.java +++ b/src/esieequest/model/characters/Sumobot.java | |||
@@ -1,9 +1,11 @@ | |||
1 | package esieequest.model.characters; | 1 | package esieequest.model.characters; |
2 | 2 | ||
3 | import java.util.HashSet; | ||
4 | import java.util.Random; | 3 | import java.util.Random; |
5 | 4 | ||
5 | import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils.Text; | ||
6 | |||
6 | import esieequest.model.Game; | 7 | import esieequest.model.Game; |
8 | import esieequest.model.events.Scene; | ||
7 | import esieequest.model.map.Direction; | 9 | import esieequest.model.map.Direction; |
8 | import esieequest.model.map.Room; | 10 | import esieequest.model.map.Room; |
9 | import esieequest.view.Viewable; | 11 | import esieequest.view.Viewable; |
@@ -15,8 +17,11 @@ import esieequest.view.Viewable; | |||
15 | */ | 17 | */ |
16 | public class Sumobot extends MovingCharacter { | 18 | public class Sumobot extends MovingCharacter { |
17 | 19 | ||
20 | private static final String INIT_MESSAGE = "Waking up..."; | ||
21 | private static final String[] MESSAGES = { "絶やす !", "あなたが削除されます。", "あなたの死が実装されます。" }; | ||
22 | private static final String KILLED_MESSAGE = "The Sumobot fatally pushed you. You died."; | ||
23 | |||
18 | private final Random randomGenerator; | 24 | private final Random randomGenerator; |
19 | private final HashSet<String> messages; | ||
20 | 25 | ||
21 | /** | 26 | /** |
22 | * Creates a Sumobot with its primary location. | 27 | * Creates a Sumobot with its primary location. |
@@ -30,21 +35,25 @@ public class Sumobot extends MovingCharacter { | |||
30 | super("Sumobot DK-02", room, direction); | 35 | super("Sumobot DK-02", room, direction); |
31 | 36 | ||
32 | this.randomGenerator = new Random(); | 37 | this.randomGenerator = new Random(); |
38 | } | ||
33 | 39 | ||
34 | this.messages = new HashSet<String>(); | 40 | private String getRandomMessage() { |
35 | // exterminate ! | 41 | final int randomIndex = this.randomGenerator.nextInt(Sumobot.MESSAGES.length); |
36 | this.messages.add("絶やす !"); | 42 | return Sumobot.MESSAGES[randomIndex]; |
37 | // you will be deleted | ||
38 | this.messages.add("あなたが削除されます。"); | ||
39 | // your death will now be implemented | ||
40 | this.messages.add("あなたの死が実装されます。"); | ||
41 | } | 43 | } |
42 | 44 | ||
43 | @Override | 45 | @Override |
44 | public void talk(final Game game, final Viewable view) { | 46 | public void talk(final Game game, final Viewable view) { |
45 | this.setCanMove(true); | 47 | |
46 | final int randomIndex = this.randomGenerator.nextInt(this.messages.size()); | 48 | if (!this.isMobile()) { |
47 | view.echo((String) this.messages.toArray()[randomIndex]); | 49 | this.setMobile(true); |
50 | view.echo(Sumobot.INIT_MESSAGE); | ||
51 | return; | ||
52 | } | ||
53 | |||
54 | view.playScene(Scene.GAME_LOST); | ||
55 | view.echo(this.getRandomMessage() + Text.NEW_LINE + Sumobot.KILLED_MESSAGE); | ||
56 | |||
48 | } | 57 | } |
49 | 58 | ||
50 | } | 59 | } |