diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ch/epfl/xblast/client/GameStateDeserializer.java | 11 | ||||
-rw-r--r-- | src/ch/epfl/xblast/client/ImageCollection.java | 4 |
2 files changed, 9 insertions, 6 deletions
diff --git a/src/ch/epfl/xblast/client/GameStateDeserializer.java b/src/ch/epfl/xblast/client/GameStateDeserializer.java index 1fb1c61..f1327e3 100644 --- a/src/ch/epfl/xblast/client/GameStateDeserializer.java +++ b/src/ch/epfl/xblast/client/GameStateDeserializer.java | |||
@@ -32,7 +32,7 @@ public final class GameStateDeserializer { | |||
32 | private final static int PLAYER_TOTAL_SIZE = NUMBER_OF_PLAYERS * PLAYER_CHUNK_SIZE; | 32 | private final static int PLAYER_TOTAL_SIZE = NUMBER_OF_PLAYERS * PLAYER_CHUNK_SIZE; |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Various | 35 | * Scores & Time |
36 | */ | 36 | */ |
37 | private final static int TIME_LINE_SIZE = (Ticks.GAME_DURATION / 2); | 37 | private final static int TIME_LINE_SIZE = (Ticks.GAME_DURATION / 2); |
38 | private final static int SCORE_SEPARATION_SIZE = 8; | 38 | private final static int SCORE_SEPARATION_SIZE = 8; |
@@ -68,7 +68,7 @@ public final class GameStateDeserializer { | |||
68 | private static List<Player> deserializePlayers(List<Byte> serializedPlayers) { | 68 | private static List<Player> deserializePlayers(List<Byte> serializedPlayers) { |
69 | List<Player> players = new ArrayList<>(); | 69 | List<Player> players = new ArrayList<>(); |
70 | 70 | ||
71 | for (int i = 0; i < NUMBER_OF_PLAYERS; i++) { | 71 | for (int i = 0; i < NUMBER_OF_PLAYERS; i++) { // ugly |
72 | players.add( | 72 | players.add( |
73 | deserializePlayer( | 73 | deserializePlayer( |
74 | serializedPlayers.subList(i * PLAYER_CHUNK_SIZE, (i+1) * PLAYER_CHUNK_SIZE), i | 74 | serializedPlayers.subList(i * PLAYER_CHUNK_SIZE, (i+1) * PLAYER_CHUNK_SIZE), i |
@@ -87,11 +87,14 @@ public final class GameStateDeserializer { | |||
87 | */ | 87 | */ |
88 | private static Player deserializePlayer(List<Byte> serializedPlayer, int i) { | 88 | private static Player deserializePlayer(List<Byte> serializedPlayer, int i) { |
89 | PlayerID id = PlayerID.values()[i]; | 89 | PlayerID id = PlayerID.values()[i]; |
90 | |||
90 | int lives = Byte.toUnsignedInt(serializedPlayer.get(0)); | 91 | int lives = Byte.toUnsignedInt(serializedPlayer.get(0)); |
92 | |||
91 | SubCell position = new SubCell( | 93 | SubCell position = new SubCell( |
92 | Byte.toUnsignedInt(serializedPlayer.get(1)), | 94 | Byte.toUnsignedInt(serializedPlayer.get(1)), |
93 | Byte.toUnsignedInt(serializedPlayer.get(2)) | 95 | Byte.toUnsignedInt(serializedPlayer.get(2)) |
94 | ); | 96 | ); |
97 | |||
95 | Image image = (new ImageCollection(PLAYER_IMAGES_FOLDER)).imageOrNull(Byte.toUnsignedInt(serializedPlayer.get(3))); | 98 | Image image = (new ImageCollection(PLAYER_IMAGES_FOLDER)).imageOrNull(Byte.toUnsignedInt(serializedPlayer.get(3))); |
96 | 99 | ||
97 | return new Player(id, lives, position, image); | 100 | return new Player(id, lives, position, image); |
@@ -164,9 +167,9 @@ public final class GameStateDeserializer { | |||
164 | * @param serializedData the serialized gameState | 167 | * @param serializedData the serialized gameState |
165 | * @return a new GameState build from the serialized data. | 168 | * @return a new GameState build from the serialized data. |
166 | */ | 169 | */ |
167 | public static GameState deserialize(List<Byte> serializedData) { | 170 | public static GameState deserialize(List<Byte> serializedData) { // Ugly |
168 | 171 | ||
169 | // Build the indexes | 172 | // Build the indexes (Ugly) |
170 | int boardBeginIndex = 0; // First element | 173 | int boardBeginIndex = 0; // First element |
171 | int boardEndIndex = (boardBeginIndex) + Byte.toUnsignedInt(serializedData.get(boardBeginIndex)); | 174 | int boardEndIndex = (boardBeginIndex) + Byte.toUnsignedInt(serializedData.get(boardBeginIndex)); |
172 | int explosionsBeginIndex = boardEndIndex + 1; | 175 | int explosionsBeginIndex = boardEndIndex + 1; |
diff --git a/src/ch/epfl/xblast/client/ImageCollection.java b/src/ch/epfl/xblast/client/ImageCollection.java index 4f54f3b..ee0e8cf 100644 --- a/src/ch/epfl/xblast/client/ImageCollection.java +++ b/src/ch/epfl/xblast/client/ImageCollection.java | |||
@@ -14,8 +14,8 @@ public final class ImageCollection { | |||
14 | /** | 14 | /** |
15 | * Bounds of the file ID in the filename. | 15 | * Bounds of the file ID in the filename. |
16 | */ | 16 | */ |
17 | private final int FILENAME_ID_BEGIN_INDEX = 0; | 17 | private static final int FILENAME_ID_BEGIN_INDEX = 0; |
18 | private final int FILENAME_ID_END_INDEX = 2; | 18 | private static final int FILENAME_ID_END_INDEX = 2; |
19 | 19 | ||
20 | /** | 20 | /** |
21 | * Directory related to the ImageCollection. | 21 | * Directory related to the ImageCollection. |