aboutsummaryrefslogtreecommitdiff
path: root/src/esieequest/game/Game.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/esieequest/game/Game.java')
-rw-r--r--src/esieequest/game/Game.java248
1 files changed, 248 insertions, 0 deletions
diff --git a/src/esieequest/game/Game.java b/src/esieequest/game/Game.java
new file mode 100644
index 0000000..92bc99f
--- /dev/null
+++ b/src/esieequest/game/Game.java
@@ -0,0 +1,248 @@
1package esieequest.game;
2
3import lombok.Getter;
4import lombok.Setter;
5import net.pacien.util.CleanJSONObject;
6
7import org.json.simple.JSONArray;
8import org.json.simple.JSONObject;
9
10import esieequest.engine.utils.SerialisableObject;
11import esieequest.game.characters.Character;
12import esieequest.game.doors.Door;
13import esieequest.game.doors.HiddenDoor;
14import esieequest.game.doors.LockedDoor;
15import esieequest.game.doors.TransporterDoor;
16import esieequest.game.doors.TrapDoor;
17import esieequest.game.items.Item;
18import esieequest.game.map.Direction;
19import esieequest.game.map.Room;
20import esieequest.game.states.Quest;
21
22/**
23 * The Game model.
24 *
25 * @author Pacien TRAN-GIRARD
26 */
27public class Game implements SerialisableObject {
28
29 public static final int DEFAULT_INVENTORY_LIMIT = 10;
30 public static final int DEFAULT_STEPS_LIMIT = 0;
31 public static final int CHALLENGE_STEPS_LIMIT = 50;
32 public static final Direction DEFAULT_DIRECTION = Direction.NORTH;
33 public static final Room DEFAULT_ROOM = Room.AMPHITHEATER_SEAT;
34 public static final Quest DEFAULT_QUEST = Quest.WHAT_HAPPENED;
35
36 private static final String CHALLENGE_LABEL = "L";
37 private final boolean challenge;
38
39 private static final String PLAYER_LABEL = "P";
40 @Getter
41 @Setter
42 private Player player;
43
44 private static final String ROOMS_LABEL = "R";
45 private static final String ITEMS_LABEL = "I";
46 private static final String CHARACTERS_LABEL = "C";
47
48 /**
49 * Creates a Game with a step limit for the Player.
50 *
51 * @param challenge
52 * the value of challenge mode
53 */
54 public Game(final boolean challenge) {
55 this.challenge = challenge;
56 }
57
58 /**
59 * Creates a Game.
60 */
61 public Game() {
62 this(false);
63 }
64
65 /**
66 * Initialises a new Game.
67 */
68 public void newGame(final boolean populate, final boolean challengeMode) {
69 Room.createAllSides();
70 this.connectRooms();
71
72 this.setPlayer(new Player(Game.DEFAULT_QUEST, Game.DEFAULT_ROOM, Game.DEFAULT_DIRECTION,
73 Game.DEFAULT_INVENTORY_LIMIT, challengeMode ? Game.CHALLENGE_STEPS_LIMIT
74 : Game.DEFAULT_STEPS_LIMIT));
75
76 if (populate) {
77 this.addItems();
78 this.addCharacters();
79 }
80 }
81
82 /**
83 * Connects Room-s together using Door-s.
84 */
85 public void connectRooms() {
86 this.d(Room.AMPHITHEATER_SEAT, Direction.NORTH, Room.AMPHITHEATER_STAGE);
87 this.d(Room.AMPHITHEATER_STAGE, Direction.WEST, Room.CAFETERIA);
88 this.d(Room.CAFETERIA, Direction.NORTH, Room.CAFETERIA_STREET);
89 this.d(Room.CAFETERIA_STREET, Direction.EAST, Room.ESIEESPACE_STREET);
90
91 this.d(Room.ESIEESPACE_STREET, Direction.SOUTH, Room.ESIEESPACE_FRONT);
92 this.d(Room.ESIEESPACE_FRONT, Direction.EAST, Room.ESIEESPACE_ENTRANCE);
93 this.d(Room.ESIEESPACE_ENTRANCE, Direction.NORTH, Room.ESIEESPACE);
94
95 this.d(Room.ESIEESPACE_STREET, Direction.EAST, Room.ENTRANCE_STREET);
96 this.d(Room.ENTRANCE_STREET, Direction.SOUTH, Room.ENTRANCE_STAIRS);
97 this.d(Room.ENTRANCE_STAIRS, Direction.SOUTH, Room.ENTRANCE_ROUNDABOUT);
98
99 this.d(Room.ENTRANCE_STREET, Direction.EAST, Room.WING_STREET);
100 this.d(Room.WING_STREET, Direction.NORTH, Room.WING_FLOOR_ONE);
101 this.d(Room.WING_FLOOR_ONE, Direction.WEST, Room.WING_STAIRS_ONE);
102 this.d(Room.WING_STAIRS_ONE, Direction.SOUTH, new Door(Room.WING_STAIRS_TWO));
103 this.d(Room.WING_STAIRS_TWO, Direction.SOUTH, new Door(Room.WING_STAIRS_ONE));
104 this.d(Room.WING_STAIRS_ONE, Direction.UP, new HiddenDoor(Room.WING_STAIRS_TWO));
105 this.d(Room.WING_STAIRS_TWO, Direction.DOWN, new HiddenDoor(Room.WING_STAIRS_ONE));
106 this.d(Room.WING_STAIRS_TWO, Direction.EAST, Room.WING_FLOOR_TWO);
107 this.d(Room.WING_FLOOR_TWO, Direction.NORTH, Room.WING_OFFICE_CORRIDOR);
108 this.d(Room.WING_OFFICE_CORRIDOR, Direction.EAST, Room.WING_OFFICE);
109
110 this.d(Room.WING_STREET, Direction.EAST, Room.CLUBNIX_STREET);
111 this.d(Room.CLUBNIX_STREET, Direction.SOUTH, Room.CLUBNIX_FRONT);
112 this.d(Room.CLUBNIX_FRONT, Direction.EAST, Room.CLUBNIX_ENTRANCE);
113 this.d(Room.CLUBNIX_ENTRANCE, Direction.NORTH, Room.CLUBNIX);
114
115 this.d(Room.WING_FLOOR_ONE, Direction.EAST, new HiddenDoor(Room.SECRET_CORRIDOR_ENTRANCE));
116 this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.WEST, new Door(Room.WING_FLOOR_ONE));
117 this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.NORTH, Room.STORAGE_ROOM);
118 this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.SOUTH, Room.SECRET_LAB);
119 this.d(Room.SECRET_CORRIDOR_ENTRANCE, Direction.EAST, Room.SECRET_CORRIDOR_END);
120 this.d(Room.SECRET_CORRIDOR_END, Direction.NORTH, new TrapDoor(Room.DEAD_END));
121
122 final LockedDoor lockedDoorEnter = new LockedDoor(Room.LOCKED_ROOM);
123 lockedDoorEnter.setKey(Item.KEYCARD);
124 this.d(Room.SECRET_CORRIDOR_END, Direction.SOUTH, lockedDoorEnter);
125
126 final LockedDoor lockedDoorExit = new LockedDoor(Room.SECRET_CORRIDOR_END);
127 lockedDoorExit.setKey(Item.KEYCARD);
128 this.d(Room.LOCKED_ROOM, Direction.NORTH, lockedDoorExit);
129
130 this.d(Room.SECRET_CORRIDOR_END, Direction.EAST, new Door(Room.TRANSPORTER_ROOM));
131 this.d(Room.TRANSPORTER_ROOM, Direction.WEST, new TransporterDoor(Room.values()));
132 }
133
134 /**
135 * Adds two Door that connect two Room-s in both ways.
136 *
137 * @param source
138 * the source Room
139 * @param direction
140 * the direction of the Door, seen from the source Room
141 * @param destination
142 * the destination Room
143 */
144 private void d(final Room source, final Direction direction, final Room destination) {
145 source.getSide(direction).setDoor(new Door(destination));
146 destination.getSide(direction.getOpposite()).setDoor(new Door(source));
147 }
148
149 /**
150 * Adds a Door to a Room.
151 *
152 * @param room
153 * the source Room
154 * @param direction
155 * the Direction of the Door in the given Room
156 * @param door
157 * the Door
158 */
159 private void d(final Room room, final Direction direction, final Door door) {
160 room.getSide(direction).setDoor(door);
161 }
162
163 /**
164 * Adds Item-s in the map.
165 */
166 public void addItems() {
167
168 // secret corridor
169 this.i(Room.STORAGE_ROOM, Direction.WEST, Item.STORAGE_CUBE);
170 this.i(Room.STORAGE_ROOM, Direction.EAST, Item.SAFETY_CUBE);
171 this.i(Room.STORAGE_ROOM, Direction.NORTH, Item.BLACK_HOLE);
172
173 this.i(Room.SECRET_LAB, Direction.SOUTH, Item.BEAMER);
174
175 this.i(Room.DEAD_END, Direction.NORTH, Item.KEYCARD);
176
177 // scenario
178 this.i(Room.AMPHITHEATER_STAGE, Direction.SOUTH, Item.NOTE);
179 this.i(Room.CAFETERIA, Direction.WEST, Item.BANANA);
180 this.i(Room.ESIEESPACE, Direction.NORTH, Item.PORTABLE_CONSOLE);
181 this.i(Room.CLUBNIX, Direction.NORTH, Item.DISK);
182
183 }
184
185 /**
186 * Adds a given Item in a Room with a Direction.
187 *
188 * @param room
189 * the Room
190 * @param direction
191 * the Direction
192 * @param item
193 * the Item
194 */
195 private void i(final Room room, final Direction direction, final Item item) {
196 room.getSide(direction).getInventory().putItem(item);
197 }
198
199 /**
200 * Adds Character-s to the map.
201 */
202 public void addCharacters() {
203
204 // secret corridor
205 this.c(Room.LOCKED_ROOM, Direction.SOUTH, Character.SUMOBOT);
206
207 // scenario
208 this.c(Room.WING_OFFICE, Direction.EAST, Character.ATHANASE);
209
210 }
211
212 /**
213 * Adds a Character in a Room with a Direction.
214 *
215 * @param room
216 * the Room
217 * @param direction
218 * the Direction
219 * @param character
220 * the Character
221 */
222 private void c(final Room room, final Direction direction, final Character character) {
223 room.getSide(direction).setCharacter(character);
224 }
225
226 @Override
227 public JSONObject serialise() {
228 final CleanJSONObject o = new CleanJSONObject();
229
230 o.put(Game.CHALLENGE_LABEL, this.challenge);