diff options
Diffstat (limited to 'src/esieequest/game/characters/Character.java')
-rw-r--r-- | src/esieequest/game/characters/Character.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/esieequest/game/characters/Character.java b/src/esieequest/game/characters/Character.java new file mode 100644 index 0000000..66250fe --- /dev/null +++ b/src/esieequest/game/characters/Character.java | |||
@@ -0,0 +1,75 @@ | |||
1 | package esieequest.game.characters; | ||
2 | |||
3 | import org.json.simple.JSONArray; | ||
4 | import org.json.simple.JSONObject; | ||
5 | |||
6 | import esieequest.engine.utils.EnumUtils; | ||
7 | import esieequest.engine.utils.SerialisableObject; | ||
8 | import esieequest.game.Game; | ||
9 | import esieequest.game.map.Direction; | ||
10 | import esieequest.game.map.Room; | ||
11 | import esieequest.ui.Viewable; | ||
12 | |||
13 | public enum Character implements SerialisableObject { | ||
14 | |||
15 | // @formatter:off | ||
16 | |||
17 | // secret corridor | ||
18 | SUMOBOT(new Sumobot(Room.LOCKED_ROOM, Direction.SOUTH)), | ||
19 | |||
20 | // scenario | ||
21 | ATHANASE(new Athanase()); | ||
22 | |||
23 | ; | ||
24 | |||
25 | // @formatter:on | ||
26 | |||
27 | private final SimpleCharacter character; | ||
28 | |||
29 | Character(final SimpleCharacter character) { | ||
30 | this.character = character; | ||
31 | } | ||
32 | |||
33 | public String getName() { | ||
34 | return this.character.getName(); | ||
35 | } | ||
36 | |||
37 | public void talk(final Game game, final Viewable view) { | ||
38 | this.character.talk(game, view); | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * @return the character | ||
43 | */ | ||
44 | public SimpleCharacter getCharacter() { | ||
45 | return this.character; | ||
46 | } | ||
47 | |||
48 | public static Character getCharacter(final SimpleCharacter simpleCharacter) { | ||
49 | for (final Character character : Character.values()) { | ||
50 | if (character.getCharacter() == simpleCharacter) { | ||
51 | return character; | ||
52 | } | ||
53 | } | ||
54 | return null; | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | public JSONObject serialise() { | ||
59 | return this.character.serialise(); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | public void deserialise(final JSONObject o) { | ||
64 | this.character.deserialise(o); | ||
65 | } | ||
66 | |||
67 | public static JSONArray serialiseAll() { | ||
68 | return EnumUtils.serialiseEnumObjects(Character.values()); | ||
69 | } | ||
70 | |||
71 | public static void deserialiseAll(final JSONArray a) { | ||
72 | EnumUtils.deserialiseEnumObjects(Character.class, a); | ||
73 | } | ||
74 | |||
75 | } | ||