aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl
diff options
context:
space:
mode:
authorTimothée Floure2016-05-08 14:15:26 +0200
committerTimothée Floure2016-05-08 14:15:26 +0200
commit03a6be12726147c494e145b543230ecbf64905e7 (patch)
tree5241af41b9bc051957481b910101395f8e1d41f2 /src/ch/epfl
parente2f344f4ff6683239dc78dc241b099570180864a (diff)
downloadxblast-03a6be12726147c494e145b543230ecbf64905e7.tar.gz
Debug the GameStateDeserializer Class
Diffstat (limited to 'src/ch/epfl')
-rw-r--r--src/ch/epfl/xblast/client/GameStateDeserializer.java35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/ch/epfl/xblast/client/GameStateDeserializer.java b/src/ch/epfl/xblast/client/GameStateDeserializer.java
index f95c515..66be2d9 100644
--- a/src/ch/epfl/xblast/client/GameStateDeserializer.java
+++ b/src/ch/epfl/xblast/client/GameStateDeserializer.java
@@ -28,8 +28,9 @@ public final class GameStateDeserializer {
28 * Serialized data chunks 28 * Serialized data chunks
29 */ 29 */
30 private final static int NUMBER_OF_PLAYERS = 4; 30 private final static int NUMBER_OF_PLAYERS = 4;
31 private final static int PLAYER_CHUNK_SIZE = 6; 31 private final static int PLAYER_CHUNK_SIZE = 4;
32 private final static int PLAYER_SIZE = NUMBER_OF_PLAYERS * PLAYER_CHUNK_SIZE; 32 private final static int PLAYER_TOTAL_SIZE = NUMBER_OF_PLAYERS * PLAYER_CHUNK_SIZE;
33
33 private final static int TIME_LINE_SIZE = (Ticks.GAME_DURATION / 2); 34 private final static int TIME_LINE_SIZE = (Ticks.GAME_DURATION / 2);
34 35
35 /** 36 /**
@@ -55,10 +56,10 @@ public final class GameStateDeserializer {
55 } 56 }
56 57
57 /** 58 /**
58 * Build a list of players given the serialized data.. 59 * Build a list of players given the serialized data.
59 * 60 *
60 * @param serializedPlayers the serialized players 61 * @param serializedPlayers the serialized players
61 * @return a list of players built from the serialized players 62 * @return a list of players built from the serialized data
62 */ 63 */
63 private static List<Player> deserializePlayers(List<Byte> serializedPlayers) { 64 private static List<Player> deserializePlayers(List<Byte> serializedPlayers) {
64 List<Player> players = new ArrayList<>(); 65 List<Player> players = new ArrayList<>();
@@ -75,10 +76,10 @@ public final class GameStateDeserializer {
75 } 76 }
76 77
77 /** 78 /**
78 * Generate a Player from the serialized data. 79 * Generate a Player from its serialized data.
79 * 80 *
80 * @param serializedPlayer a serialized player 81 * @param serializedPlayer a serialized player
81 * @return a player built from the serialized player 82 * @return a player built from its serialized data
82 */ 83 */
83 private static Player deserializePlayer(List<Byte> serializedPlayer, int i) { 84 private static Player deserializePlayer(List<Byte> serializedPlayer, int i) {
84 PlayerID id = PlayerID.values()[i]; 85 PlayerID id = PlayerID.values()[i];
@@ -126,6 +127,7 @@ public final class GameStateDeserializer {
126 playerScore.add(imageCollection.imageOrNull(SCORE_TEXT_RIGHT_IMAGE_ID)); 127 playerScore.add(imageCollection.imageOrNull(SCORE_TEXT_RIGHT_IMAGE_ID));
127 return playerScore; 128 return playerScore;
128 } 129 }
130
129 /** 131 /**
130 * Generate the list of images composing the time "line". 132 * Generate the list of images composing the time "line".
131 * 133 *
@@ -153,28 +155,29 @@ public final class GameStateDeserializer {
153 */ 155 */
154 public static GameState deserialize(List<Byte> serializedData) { 156 public static GameState deserialize(List<Byte> serializedData) {
155 157
156 // Indexes 158 // Build the indexes
157 int boardIndex = 1; 159 int boardBeginIndex = 0; // First element
158 int boardSize = serializedData.get(boardIndex); 160 int boardEndIndex = (boardBeginIndex) + Byte.toUnsignedInt(serializedData.get(boardBeginIndex));
159 int explosionsIndex = boardIndex + boardSize; 161 int explosionsBeginIndex = boardEndIndex + 1;
160 int explosionsSize = serializedData.get(explosionsIndex); 162 int explosionsEndIndex = explosionsBeginIndex + Byte.toUnsignedInt(serializedData.get(explosionsBeginIndex));
161 int playersIndex = explosionsIndex + explosionsSize; 163 int playersBeginIndex = explosionsEndIndex + 1;
162 Byte time = serializedData.get(serializedData.size()); 164 int playersEndIndex = (playersBeginIndex - 1) + PLAYER_TOTAL_SIZE;
165 Byte time = serializedData.get(playersEndIndex + 1); // Last element
163 166
164 // Deserialize the Board 167 // Deserialize the Board
165 List<Image> board = deserializeChunk( 168 List<Image> board = deserializeChunk(
166 serializedData.subList(boardIndex, boardSize), 169 serializedData.subList(boardBeginIndex + 1, boardEndIndex + 1),
167 new ImageCollection(BOARD_IMAGES_FOLDER) 170 new ImageCollection(BOARD_IMAGES_FOLDER)
168 ); 171 );
169 172
170 // Deserialize the explosions 173 // Deserialize the explosions
171 List<Image> explosions = deserializeChunk( 174 List<Image> explosions = deserializeChunk(
172 serializedData.subList(boardIndex,boardSize), 175 serializedData.subList(explosionsBeginIndex + 1,explosionsEndIndex + 1),
173 new ImageCollection(EXPLOSION_IMAGES_FOLDER) 176 new ImageCollection(EXPLOSION_IMAGES_FOLDER)
174 ); 177 );
175 178
176 // Deserialize the players 179 // Deserialize the players
177 List<Player> players = deserializePlayers(serializedData.subList(playersIndex,PLAYER_SIZE)); 180 List<Player> players = deserializePlayers(serializedData.subList(playersBeginIndex,playersEndIndex + 1));
178 181
179 // Generate the scores and the time "line" 182 // Generate the scores and the time "line"
180 List<Image> scores = buildScores(players); 183 List<Image> scores = buildScores(players);